Skip to content

Commit 5dfd15f

Browse files
committed
return length directly
1 parent 75be8ee commit 5dfd15f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

codeflash/code_utils/code_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from codeflash.cli_cmds.console import logger
1212

13-
def encode_str(s: str) -> str:
14-
return s[:len(s)//2]
13+
def encode_str(s: str) -> int:
14+
return len(s)//2
1515

1616
def get_qualified_name(module_name: str, full_qualified_name: str) -> str:
1717
if not full_qualified_name:

codeflash/context/code_context_extractor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_code_optimization_context(
7272
)
7373

7474
# Handle token limits
75-
final_read_writable_tokens = len(encode_str(final_read_writable_code))
75+
final_read_writable_tokens = encode_str(final_read_writable_code)
7676
if final_read_writable_tokens > optim_token_limit:
7777
raise ValueError("Read-writable code has exceeded token limit, cannot proceed")
7878

@@ -85,7 +85,7 @@ def get_code_optimization_context(
8585
)
8686
read_only_context_code = read_only_code_markdown.markdown
8787

88-
read_only_code_markdown_tokens = len(encode_str(read_only_context_code))
88+
read_only_code_markdown_tokens = encode_str(read_only_context_code)
8989
total_tokens = final_read_writable_tokens + read_only_code_markdown_tokens
9090
if total_tokens > optim_token_limit:
9191
logger.debug("Code context has exceeded token limit, removing docstrings from read-only code")
@@ -94,7 +94,7 @@ def get_code_optimization_context(
9494
helpers_of_fto_dict, helpers_of_helpers_dict, project_root_path, remove_docstrings=True
9595
)
9696
read_only_context_code = read_only_code_no_docstring_markdown.markdown
97-
read_only_code_no_docstring_markdown_tokens = len(encode_str(read_only_context_code))
97+
read_only_code_no_docstring_markdown_tokens = encode_str(read_only_context_code)
9898
total_tokens = final_read_writable_tokens + read_only_code_no_docstring_markdown_tokens
9999
if total_tokens > optim_token_limit:
100100
logger.debug("Code context has exceeded token limit, removing read-only code")
@@ -109,7 +109,7 @@ def get_code_optimization_context(
109109
code_context_type=CodeContextType.TESTGEN,
110110
)
111111
testgen_context_code = testgen_code_markdown.code
112-
testgen_context_code_tokens = len(encode_str(testgen_context_code))
112+
testgen_context_code_tokens = encode_str(testgen_context_code)
113113
if testgen_context_code_tokens > testgen_token_limit:
114114
testgen_code_markdown = extract_code_string_context_from_files(
115115
helpers_of_fto_dict,
@@ -119,7 +119,7 @@ def get_code_optimization_context(
119119
code_context_type=CodeContextType.TESTGEN,
120120
)
121121
testgen_context_code = testgen_code_markdown.code
122-
testgen_context_code_tokens = len(encode_str(testgen_context_code))
122+
testgen_context_code_tokens = encode_str(testgen_context_code)
123123
if testgen_context_code_tokens > testgen_token_limit:
124124
raise ValueError("Testgen code context has exceeded token limit, cannot proceed")
125125

0 commit comments

Comments
 (0)