5
5
from pathlib import Path
6
6
7
7
import hydra
8
+ from datasets import load_dataset
9
+ from omegaconf import OmegaConf
10
+ from tqdm .contrib .concurrent import thread_map
11
+
8
12
from baselines .baseline_utils import (
9
13
PROMPT_HEADER ,
10
14
REFERENCE_HEADER ,
16
20
get_reference ,
17
21
)
18
22
from baselines .class_types import AiderConfig , BaselineConfig , Commit0Config
19
- from datasets import load_dataset
20
- from omegaconf import OmegaConf
21
- from tqdm .contrib .concurrent import thread_map
22
23
23
24
# from aider.run_aider import get_aider_cmd
24
25
30
31
31
32
def get_aider_cmd (
32
33
model : str ,
33
- file : str ,
34
- prompt : str ,
35
- reference : str ,
36
- repo_info : str ,
37
- unit_tests_info : str ,
34
+ files : str ,
35
+ message_to_aider : str ,
38
36
test_cmd : str ,
39
37
) -> str :
40
38
"""Get the Aider command based on the given context."""
41
- message = f"{ PROMPT_HEADER } { prompt } "
42
- if reference :
43
- message += f"\n { REFERENCE_HEADER } { reference } "
44
- if repo_info :
45
- message += f"\n { REPO_INFO_HEADER } { repo_info } "
46
- if unit_tests_info :
47
- message += f"\n { UNIT_TESTS_INFO_HEADER } { unit_tests_info } "
48
-
49
- aider_cmd = f"aider --model { model } --file { file } --message \" { message } \" --auto-test --test --test-cmd '{ test_cmd } ' --yes"
39
+ aider_cmd = f"aider --model { model } --file { files } --message \" { message_to_aider } \" --auto-test --test --test-cmd '{ test_cmd } ' --yes"
50
40
51
41
return aider_cmd
52
42
@@ -57,54 +47,54 @@ def run_aider_for_repo(
57
47
ds : dict ,
58
48
) -> None :
59
49
"""Run Aider for a given repository."""
60
- if commit0_config is None or aider_config is None or ds is None :
50
+ if commit0_config is None or aider_config is None :
61
51
raise ValueError ("Invalid input" )
62
52
63
53
# get repo info
64
54
_ , repo_name = ds ["repo" ].split ("/" )
65
55
66
- # TODO: assuming we have all test_files
56
+ # TODO: assuming we have all test_files, which we currently do not have
67
57
test_files = ds ["test_files" ]
68
58
69
59
repo_path = os .path .join (commit0_config .base_dir , repo_name )
70
60
target_edit_files = find_files_with_error (repo_path )
71
61
72
62
target_edit_files_cmd_args = " " .join (target_edit_files )
73
63
74
- prompt = get_prompt (target_edit_files_cmd_args )
64
+ prompt = f" { PROMPT_HEADER } " + get_prompt (target_edit_files_cmd_args )
75
65
76
66
# support context for aider
77
67
if aider_config .use_unit_tests_info and ds ["test" ]["test_dir" ]:
78
- unit_tests_info = get_dir_info (
68
+ unit_tests_info = f" \n { UNIT_TESTS_INFO_HEADER } " + get_dir_info (
79
69
dir_path = Path (os .path .join (repo_path , ds ["test" ]["test_dir" ])),
80
70
prefix = "" ,
81
71
include_stubs = True ,
82
72
)
83
73
else :
84
74
unit_tests_info = ""
85
75
76
+ # TODO: assuming we have specification, which we currently do not have
86
77
if aider_config .use_reference_info and ds ["specification" ]:
87
- reference = get_reference (ds ["specification" ])
78
+ reference = f" \n { REFERENCE_HEADER } " + get_reference (ds ["specification" ])
88
79
else :
89
80
reference = ""
90
81
91
82
if aider_config .use_repo_info :
92
- repo_info = get_dir_info (
83
+ repo_info = f" \n { REPO_INFO_HEADER } " + get_dir_info (
93
84
dir_path = Path (repo_path ), prefix = "" , max_depth = 2 , include_stubs = False
94
85
)
95
86
else :
96
87
repo_info = ""
97
88
89
+ message_to_aider = prompt + reference + repo_info + unit_tests_info
90
+
98
91
for test_file in test_files :
99
92
test_cmd = f"python -m commit0.harness.run_pytest_ids --repo { repo_name } --test_ids { test_file } --branch_name aider"
100
93
101
94
aider_cmd = get_aider_cmd (
102
95
aider_config .llm_name ,
103
96
target_edit_files_cmd_args ,
104
- prompt ,
105
- reference ,
106
- repo_info ,
107
- unit_tests_info ,
97
+ message_to_aider ,
108
98
test_cmd ,
109
99
)
110
100
@@ -128,7 +118,10 @@ def run_aider_for_repo(
128
118
129
119
@hydra .main (version_base = None , config_path = "config" , config_name = "aider" )
130
120
def main (config : BaselineConfig ) -> None :
131
- """Main function to run Aider for a given repository. Will run in parallel for each repo."""
121
+ """Main function to run Aider for a given repository.
122
+
123
+ Will run in parallel for each repo.
124
+ """
132
125
config = BaselineConfig (config = OmegaConf .to_object (config ))
133
126
commit0_config = config .commit0_config
134
127
aider_config = config .aider_config
0 commit comments