Skip to content

Commit bccffd4

Browse files
authored
Merge pull request OpenAutoCoder#40 from brutalsavage/main
feat: support claude 3.5 Sonnet with multi-file edits
2 parents c0d3ee6 + 59dc4b7 commit bccffd4

9 files changed

Lines changed: 706 additions & 148 deletions

File tree

agentless/fl/FL.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class LLMFL(FL):
8484
{file_content}
8585
```
8686
"""
87+
8788
obtain_relevant_code_combine_top_n_prompt = """
8889
Please review the following GitHub problem description and relevant files, and provide a set of locations that need to be edited to fix the issue.
8990
The locations can be specified as class names, function or method names, or exact line numbers that require modification.
@@ -97,6 +98,8 @@ class LLMFL(FL):
9798
###
9899
99100
Please provide the class name, function or method name, or the exact line numbers that need to be edited.
101+
The possible location outputs should be either "class", "function" or "line".
102+
100103
### Examples:
101104
```
102105
full_path1/file1.py
@@ -114,7 +117,7 @@ class LLMFL(FL):
114117
line: 156
115118
```
116119
117-
Return just the location(s)
120+
Return just the location(s) wrapped with ```.
118121
"""
119122

120123
obtain_relevant_code_combine_top_n_no_line_number_prompt = """
@@ -144,7 +147,7 @@ class LLMFL(FL):
144147
function: my_function2
145148
```
146149
147-
Return just the location(s)
150+
Return just the location(s) wrapped with ```.
148151
"""
149152
obtain_relevant_functions_and_vars_from_compressed_files_prompt_more = """
150153
Please look through the following GitHub Problem Description and the Skeleton of Relevant Files.
@@ -180,7 +183,7 @@ class LLMFL(FL):
180183
class: MyClass5
181184
```
182185
183-
Return just the locations.
186+
Return just the locations wrapped with ```.
184187
"""
185188

186189
obtain_relevant_functions_and_vars_from_raw_files_prompt = """
@@ -217,7 +220,7 @@ class LLMFL(FL):
217220
class: MyClass5
218221
```
219222
220-
Return just the locations.
223+
Return just the locations wrapped with ```.
221224
"""
222225

223226
def __init__(
@@ -577,7 +580,35 @@ def localize_line_from_coarse_function_locs(
577580
)
578581
self.logger.info(f"prompting with message:\n{message}")
579582
self.logger.info("=" * 80)
580-
assert num_tokens_from_messages(message, self.model_name) < MAX_CONTEXT_LENGTH
583+
584+
def message_too_long(message):
585+
return (
586+
num_tokens_from_messages(message, self.model_name) >= MAX_CONTEXT_LENGTH
587+
)
588+
589+
while message_too_long(message) and len(coarse_locs) > 1:
590+
self.logger.info(f"reducing to \n{len(coarse_locs)} files")
591+
coarse_locs.popitem()
592+
topn_content, file_loc_intervals = construct_topn_file_context(
593+
coarse_locs,
594+
file_names,
595+
file_contents,
596+
self.structure,
597+
context_window=context_window,
598+
loc_interval=True,
599+
add_space=add_space,
600+
sticky_scroll=sticky_scroll,
601+
no_line_number=no_line_number,
602+
)
603+
message = template.format(
604+
problem_statement=self.problem_statement, file_contents=topn_content
605+
)
606+
607+
if message_too_long(message):
608+
raise ValueError(
609+
"The remaining file content is too long to fit within the context length"
610+
)
611+
581612
if mock:
582613
self.logger.info("Skipping querying model since mock=True")
583614
traj = {
@@ -596,7 +627,9 @@ def localize_line_from_coarse_function_locs(
596627
temperature=temperature,
597628
batch_size=num_samples,
598629
)
599-
raw_trajs = model.codegen(message, num_samples=num_samples)
630+
raw_trajs = model.codegen(
631+
message, num_samples=num_samples, prompt_cache=num_samples > 1
632+
)
600633

601634
# Merge trajectories
602635
raw_outputs = [raw_traj["response"] for raw_traj in raw_trajs]

agentless/fl/localize.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,18 @@ def main():
572572
"--model",
573573
type=str,
574574
default="gpt-4o-2024-05-13",
575-
choices=["gpt-4o-2024-05-13", "deepseek-coder", "gpt-4o-mini-2024-07-18"],
575+
choices=[
576+
"gpt-4o-2024-05-13",
577+
"deepseek-coder",
578+
"gpt-4o-mini-2024-07-18",
579+
"claude-3-5-sonnet-20241022",
580+
],
576581
)
577582
parser.add_argument(
578-
"--backend", type=str, default="openai", choices=["openai", "deepseek"]
583+
"--backend",
584+
type=str,
585+
default="openai",
586+
choices=["openai", "deepseek", "anthropic"],
579587
)
580588
parser.add_argument(
581589
"--dataset",

0 commit comments

Comments
 (0)