Elffuss BraidHub

kikocis/auto-code-rover public

Reformat
Changeseteba410d8d60724ebc33bf3206f7af31d3669cb3422b08f51ebfbe33e065991b1
AuthorMartin Mirchev <mmirchev@comp.nus.edu.sg> · 2024-06-08 18:13 +08:00
CommitterMartin Mirchev <mmirchev@comp.nus.edu.sg> · 2024-06-08 18:13 +08:00
Parentsb5e8b533440a

Browse the files at this changeset

12 files changed

modified app/analysis/sbfl.py +4 −8
@@ -372,16 +372,14 @@
372372 )
373373 Path(log_file).write_text(cp.stdout)
374374 except TimeoutExpired:
375- log.log_and_print(
376- "Timeout expired while running the test suite.",
377- )
375+ log.log_and_print("Timeout expired while running the test suite.")
378376 return "", log_file
379377
380378 # (3) check whether the coverage file is there
381379 cov_file = pjoin(execution_dir, ".coverage")
382380 if not os.path.exists(cov_file):
383381 log.log_and_print(
384- "Coverage file is not produced after running the test suite.",
382+ "Coverage file is not produced after running the test suite."
385383 )
386384 return "", log_file
387385 return cov_file, log_file
@@ -450,9 +448,7 @@
450448 Path(log_file).write_text(cp.stdout)
451449 # Path(self.output_dir, "run_developer_tests.log").write_text(cp.stdout)
452450 except TimeoutExpired:
453- log.log_and_print(
454- "Timeout expired while running the test suite.",
455- )
451+ log.log_and_print("Timeout expired while running the test suite.")
456452 return "", log_file
457453
458454 # (2) check whether the coverage file is there
@@ -469,7 +465,7 @@
469465 # now check again
470466 if not os.path.exists(cov_file):
471467 log.log_and_print(
472- "Coverage file is not produced after running the test suite.",
468+ "Coverage file is not produced after running the test suite."
473469 )
474470 return "", log_file
475471 return cov_file, log_file
modified app/api/eval_helper.py +4 −16
@@ -269,14 +269,8 @@
269269 p2p_failure.append(test_case)
270270
271271 results = {
272- FAIL_TO_PASS: {
273- "success": f2p_success,
274- "failure": f2p_failure,
275- },
276- PASS_TO_PASS: {
277- "success": p2p_success,
278- "failure": p2p_failure,
279- },
272+ FAIL_TO_PASS: {"success": f2p_success, "failure": f2p_failure},
273+ PASS_TO_PASS: {"success": p2p_success, "failure": p2p_failure},
280274 }
281275
282276 f2f_success = []
@@ -300,14 +294,8 @@
300294
301295 results.update(
302296 {
303- FAIL_TO_FAIL: {
304- "success": f2f_success,
305- "failure": f2f_failure,
306- },
307- PASS_TO_FAIL: {
308- "success": p2f_success,
309- "failure": p2f_failure,
310- },
297+ FAIL_TO_FAIL: {"success": f2f_success, "failure": f2f_failure},
298+ PASS_TO_FAIL: {"success": p2f_success, "failure": p2f_failure},
311299 }
312300 )
313301 return results
modified app/inference.py +4 −13
@@ -281,24 +281,15 @@
281281 found |= call_is_ok
282282
283283 if (not found) and method_name and class_name:
284- kwargs = {
285- "method_name": method_name,
286- "class_name": class_name,
287- }
284+ kwargs = {"method_name": method_name, "class_name": class_name}
288285 call_function("search_method_in_class", kwargs)
289286
290287 if (not found) and method_name and file_name:
291- kwargs = {
292- "method_name": method_name,
293- "file_name": file_name,
294- }
288+ kwargs = {"method_name": method_name, "file_name": file_name}
295289 call_function("search_method_in_file", kwargs)
296290
297291 if (not found) and class_name and file_name:
298- kwargs = {
299- "class_name": class_name,
300- "file_name": file_name,
301- }
292+ kwargs = {"class_name": class_name, "file_name": file_name}
302293 call_function("search_class_in_file", kwargs)
303294
304295 if (not found) and class_name:
@@ -367,7 +358,7 @@
367358 # good case in which we can check function call
368359 func_call_intent: FunctionCallIntent = func_call_intents[0]
369360 log_and_print(
370- f"{colored('This round model response (function call):', 'blue')} {func_call_intent}",
361+ f"{colored('This round model response (function call):', 'blue')} {func_call_intent}"
371362 )
372363 # dispatch this function call
373364 this_model_response = res_text
modified app/log.py +4 −20
@@ -74,11 +74,7 @@
7474 title = name
7575
7676 panel = Panel(
77- markdown,
78- title=title,
79- title_align="left",
80- border_style="magenta",
81- width=WIDTH,
77+ markdown, title=title, title_align="left", border_style="magenta", width=WIDTH
8278 )
8379 console.print(panel)
8480
@@ -104,11 +100,7 @@
104100 title = name
105101
106102 panel = Panel(
107- markdown,
108- title=title,
109- title_align="left",
110- border_style="blue",
111- width=WIDTH,
103+ markdown, title=title, title_align="left", border_style="blue", width=WIDTH
112104 )
113105 console.print(panel)
114106 if print_callback:
@@ -137,11 +129,7 @@
137129 title = name
138130
139131 panel = Panel(
140- markdown,
141- title=title,
142- title_align="left",
143- border_style="yellow",
144- width=WIDTH,
132+ markdown, title=title, title_align="left", border_style="yellow", width=WIDTH
145133 )
146134 console.print(panel)
147135 if print_callback:
@@ -160,11 +148,7 @@
160148
161149 title = "Issue description"
162150 panel = Panel(
163- content,
164- title=title,
165- title_align="left",
166- border_style="red",
167- width=WIDTH,
151+ content, title=title, title_align="left", border_style="red", width=WIDTH
168152 )
169153 console.print(panel)
170154
modified app/main.py +9 −31
@@ -40,8 +40,7 @@
4040 set_swe_parser_args(swe_parser)
4141
4242 github_parser = subparsers.add_parser(
43- "github-issue",
44- help="Run an online github issue",
43+ "github-issue", help="Run an online github issue"
4544 )
4645 set_github_parser_args(github_parser)
4746
@@ -104,11 +103,7 @@
104103 setup_dir = abspath(setup_dir)
105104
106105 task = RawGithubTask(
107- args.task_id,
108- args.clone_link,
109- args.commit_hash,
110- args.issue_link,
111- setup_dir,
106+ args.task_id, args.clone_link, args.commit_hash, args.issue_link, setup_dir
112107 )
113108 groups = {"github": [task]}
114109 run_task_groups(groups, num_processes)
@@ -119,11 +114,7 @@
119114 issue_file = args.issue_file
120115 if issue_file is not None:
121116 issue_file = abspath(issue_file)
122- task = RawLocalTask(
123- args.task_id,
124- local_repo,
125- issue_file,
126- )
117+ task = RawLocalTask(args.task_id, local_repo, issue_file)
127118 groups = {"local": [task]}
128119 run_task_groups(groups, num_processes)
129120 elif subcommand == "extract-patches":
@@ -156,14 +147,10 @@
156147 def set_github_parser_args(parser: ArgumentParser) -> None:
157148 add_task_related_args(parser)
158149 parser.add_argument(
159- "--task-id",
160- type=str,
161- help="Assign an id to the current fresh issue task.",
150+ "--task-id", type=str, help="Assign an id to the current fresh issue task."
162151 )
163152 parser.add_argument(
164- "--clone-link",
165- type=str,
166- help="The link to the repository to clone.",
153+ "--clone-link", type=str, help="The link to the repository to clone."
167154 )
168155 parser.add_argument("--commit-hash", type=str, help="The commit hash to checkout.")
169156 parser.add_argument("--issue-link", type=str, help="The link to the issue.")
@@ -370,17 +357,14 @@
370357
371358
372359 def run_task_groups_parallel(
373- task_groups: Mapping[str, Sequence[RawTask]],
374- num_processes: int,
360+ task_groups: Mapping[str, Sequence[RawTask]], num_processes: int
375361 ):
376362 num_task_groups = len(task_groups)
377363 globals_mut.init_total_num_task_groups(num_task_groups)
378364 num_processes = min(num_processes, num_task_groups)
379365
380366 task_group_ids_items = sorted(
381- task_groups.items(),
382- key=lambda x: len(x[1]),
383- reverse=True,
367+ task_groups.items(), key=lambda x: len(x[1]), reverse=True
384368 )
385369 log.print_with_time(f"Sorted task groups: {[x[0] for x in task_group_ids_items]}")
386370 try:
@@ -437,9 +421,7 @@
437421
438422 task.dump_meta_data(task_output_dir)
439423
440- log.log_and_always_print(
441- f"============= Running task {task_id} =============",
442- )
424+ log.log_and_always_print(f"============= Running task {task_id} =============")
443425
444426 run_ok = False
445427
@@ -516,11 +498,7 @@
516498 return run_ok
517499
518500
519-def dump_cost(
520- start_time: datetime,
521- end_time: datetime,
522- task_output_dir: str,
523-):
501+def dump_cost(start_time: datetime, end_time: datetime, task_output_dir: str):
524502 model_stats = common.SELECTED_MODEL.get_overall_exec_stats()
525503 stats = {
526504 "commit": apputils.get_current_commit_hash(),
modified app/model/bedrock.py +27 −9
@@ -4,7 +4,6 @@
44
55 import os
66 import sys
7-
87 from typing import Literal
98
109 import litellm
@@ -42,7 +41,7 @@
4241 super().__init__(name, cost_per_input, cost_per_output, parallel_tool_call)
4342 self._model_provider = self.name.split(".")[0]
4443 self._initialized = True
45-
44+
4645 def setup(self) -> None:
4746 """
4847 Check API key.
@@ -54,10 +53,14 @@
5453 required_env_vars = [
5554 "AWS_ACCESS_KEY_ID",
5655 "AWS_SECRET_ACCESS_KEY",
57- "AWS_REGION_NAME"
56+ "AWS_REGION_NAME",
5857 ]
59- if len(set(os.environ).intersection(required_env_vars)) != len(required_env_vars):
60- print(f"Missing env vars. Please refer to https://litellm.vercel.app/docs/providers/bedrock")
58+ if len(set(os.environ).intersection(required_env_vars)) != len(
59+ required_env_vars
60+ ):
61+ print(
62+ "Missing env vars. Please refer to https://litellm.vercel.app/docs/providers/bedrock"
63+ )
6164 sys.exit(1)
6265 return os.getenv(required_env_vars[-1])
6366
@@ -122,16 +125,25 @@
122125 log_and_print("Context length exceeded")
123126 raise e
124127
128+
125129 class AnthropicClaude2(BedrockModel):
126130 def __init__(self):
127- super().__init__("bedrock/anthropic.claude-v2:1", 0.00000025, 0.00000125,parallel_tool_call= True)
131+ super().__init__(
132+ "bedrock/anthropic.claude-v2:1",
133+ 0.00000025,
134+ 0.00000125,
135+ parallel_tool_call=True,
136+ )
128137 self.note = "Older Claude model"
129138
130139
131140 class AnthropicClaude3Opus(BedrockModel):
132141 def __init__(self):
133142 super().__init__(
134- "bedrock/anthropic.claude-3-opus-20240229-v1:0", 0.000015, 0.000075, parallel_tool_call=True
143+ "bedrock/anthropic.claude-3-opus-20240229-v1:0",
144+ 0.000015,
145+ 0.000075,
146+ parallel_tool_call=True,
135147 )
136148 self.note = "Most powerful model from Antropic"
137149
@@ -139,7 +151,10 @@
139151 class AnthropicClaude3Sonnet(BedrockModel):
140152 def __init__(self):
141153 super().__init__(
142- "bedrock/anthropic.claude-3-sonnet-20240229-v1:0", 0.000003, 0.000015, parallel_tool_call=True
154+ "bedrock/anthropic.claude-3-sonnet-20240229-v1:0",
155+ 0.000003,
156+ 0.000015,
157+ parallel_tool_call=True,
143158 )
144159 self.note = "Most balanced (intelligence and speed) model from Antropic"
145160
@@ -147,6 +162,9 @@
147162 class AnthropicClaude3Haiku(BedrockModel):
148163 def __init__(self):
149164 super().__init__(
150- "bedrock/anthropic.claude-3-haiku-20240307-v1:0", 0.00000025, 0.00000125, parallel_tool_call=True
165+ "bedrock/anthropic.claude-3-haiku-20240307-v1:0",
166+ 0.00000025,
167+ 0.00000125,
168+ parallel_tool_call=True,
151169 )
152170 self.note = "Fastest model from Antropic"
modified app/model/gpt.py +1 −2
@@ -84,8 +84,7 @@
8484 return content
8585
8686 def extract_resp_func_calls(
87- self,
88- chat_completion_message: ChatCompletionMessage,
87+ self, chat_completion_message: ChatCompletionMessage
8988 ) -> list[FunctionCallIntent]:
9089 """
9190 Given a chat completion message, extract the function calls from it.
modified app/model/ollama.py +1 −4
@@ -119,10 +119,7 @@
119119 assert self.client is not None
120120 try:
121121 # build up options for ollama
122- options = {
123- "temperature": common.MODEL_TEMP,
124- "top_p": top_p,
125- }
122+ options = {"temperature": common.MODEL_TEMP, "top_p": top_p}
126123 if response_format == "json_object":
127124 # additional instructions for json mode
128125 json_instruction = {
modified app/model/register.py +1 −1
@@ -18,7 +18,7 @@
1818 common.register_model(claude.Claude3Opus())
1919 common.register_model(claude.Claude3Sonnet())
2020 common.register_model(claude.Claude3Haiku())
21-
21+
2222 common.register_model(bedrock.AnthropicClaude3Opus())
2323 common.register_model(bedrock.AnthropicClaude3Sonnet())
2424 common.register_model(bedrock.AnthropicClaude3Haiku())
modified app/raw_tasks.py +2 −6
@@ -126,9 +126,7 @@
126126 "problem_statement": self.problem_statement,
127127 "instance_id": self.task_id,
128128 },
129- "setup_info": {
130- "repo_path": self.clone_path,
131- },
129+ "setup_info": {"repo_path": self.clone_path},
132130 }
133131
134132 meta_file = pjoin(output_dir, "meta.json")
@@ -221,9 +219,7 @@
221219 "problem_statement": self.problem_statement,
222220 "instance_id": self.task_id,
223221 },
224- "setup_info": {
225- "repo_path": self.local_repo,
226- },
222+ "setup_info": {"repo_path": self.local_repo},
227223 }
228224
229225 meta_file = pjoin(output_dir, "meta.json")
modified app/task.py +3 −9
@@ -128,10 +128,7 @@
128128
129129 # (2) install
130130 cp = apputils.run_string_cmd_in_conda(
131- task.install_cmd,
132- task.env_name,
133- capture_output=True,
134- text=True,
131+ task.install_cmd, task.env_name, capture_output=True, text=True
135132 )
136133 if cp.returncode != 0:
137134 log_and_print(cp.stderr)
@@ -141,10 +138,7 @@
141138 "python -m pip install xmlrunner coverage pytest pytest-cov"
142139 )
143140 cp = apputils.run_string_cmd_in_conda(
144- other_install_cmd,
145- task.env_name,
146- capture_output=True,
147- text=True,
141+ other_install_cmd, task.env_name, capture_output=True, text=True
148142 )
149143 if cp.returncode != 0:
150144 log_and_print(cp.stderr)
@@ -195,7 +189,7 @@
195189 app_utils.repo_clean_changes()
196190
197191 log_and_print(
198- f"[Validation] Finishing. Result is {tests_passed}. Message: {msg}.",
192+ f"[Validation] Finishing. Result is {tests_passed}. Message: {msg}."
199193 )
200194 return tests_passed, msg, log_file
201195
modified app/utils.py +3 −5
@@ -156,9 +156,7 @@
156156 submodule_unbind_cmd = ["git", "submodule", "deinit", "-f", "."]
157157 submodule_init_cmd = ["git", "submodule", "update", "--init"]
158158 run_command(
159- submodule_unbind_cmd,
160- stdout=subprocess.DEVNULL,
161- stderr=subprocess.DEVNULL,
159+ submodule_unbind_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
162160 )
163161 run_command(
164162 submodule_init_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
@@ -302,11 +300,11 @@
302300 log_and_print(
303301 f"Refactored invocation argument parsing gives different result on "
304302 f"{invocation_str!r}: old result is {arguments!r}, new result "
305- f" is {new_arguments!r}",
303+ f" is {new_arguments!r}"
306304 )
307305 except Exception as e:
308306 log_and_print(
309- f"Refactored invocation argument parsing failed on {invocation_str!r}: {e!s}",
307+ f"Refactored invocation argument parsing failed on {invocation_str!r}: {e!s}"
310308 )
311309 except Exception as e:
312310 raise ValueError(f"Invalid function invocation: {invocation_str}") from e