44import hydra
55from datasets import load_dataset
66import traceback
7- from baselines .baseline_utils import (
8- get_message_to_aider ,
7+ from baselines .commit0_utils import (
8+ get_message ,
99 get_target_edit_files ,
1010)
11+ from baselines .agents import AiderAgents
1112from typing import Optional , Type
1213from types import TracebackType
1314from hydra .core .config_store import ConfigStore
14- from baselines .class_types import AiderConfig , Commit0Config
15+ from baselines .class_types import AgentConfig , Commit0Config
1516from commit0 .harness .constants import SPLIT
1617from commit0 .harness .get_pytest_ids import main as get_tests
1718from tqdm import tqdm
1819from concurrent .futures import ThreadPoolExecutor , as_completed
1920from commit0 .harness .constants import RUN_AIDER_LOG_DIR
2021
21- from aider .coders import Coder
22- from aider .models import Model
23- from aider .io import InputOutput
24-
2522
2623class DirContext :
2724 def __init__ (self , d ):
@@ -38,33 +35,9 @@ def __exit__(
3835 os .chdir (self .cwd )
3936
4037
41- def run_aider (
42- model_name : str ,
43- fnames : list [str ],
44- message : str ,
45- test_cmd : str ,
46- lint_cmd : str ,
47- log_dir : Path ,
48- ) -> None :
49- if test_cmd :
50- auto_test = True
51- else :
52- auto_test = False
53- if lint_cmd :
54- auto_lint = True
55- else :
56- auto_lint = False
57- model = Model (model_name )
58- input_history_file = log_dir / ".aider.input.history"
59- chat_history_file = log_dir / ".aider.chat.history.md"
60- io = InputOutput (yes = True , input_history_file = input_history_file , chat_history_file = chat_history_file )
61- coder = Coder .create (main_model = model , fnames = fnames , auto_lint = auto_lint , lint_cmds = lint_cmd , io = io )
62- coder .run (message )
63-
64-
65- def run_aider_for_repo (
38+ def run_agent_for_repo (
6639 commit0_config : Commit0Config | None ,
67- aider_config : AiderConfig | None ,
40+ agent_config : AgentConfig | None ,
6841 ds : dict ,
6942) -> None :
7043 """Run Aider for a given repository."""
@@ -83,59 +56,42 @@ def run_aider_for_repo(
8356
8457 target_edit_files = get_target_edit_files (repo_path )
8558
59+ if agent_config .agent_name == "aider" :
60+ agent = AiderAgents (agent_config .model_name )
61+ else :
62+ raise NotImplementedError (f"{ agent_config .agent } is not implemented; please add your implementations in baselines/agents.py." )
63+
8664 with DirContext (repo_path ):
87- if commit0_config is None or aider_config is None :
65+ if commit0_config is None or agent_config is None :
8866 raise ValueError ("Invalid input" )
8967
90- message_to_aider = get_message_to_aider (
91- aider_config , target_edit_files , repo_path , ds
68+ message = get_message (
69+ agent_config , target_edit_files , repo_path , ds
9270 )
9371
94- if aider_config .use_lint_info :
72+ if agent_config .use_lint_info :
9573 lint_cmd = "pre-commit run --config ../../.pre-commit-config.yaml --files"
9674 else :
9775 lint_cmd = ""
9876
99- if aider_config .run_tests :
77+ if agent_config .run_tests :
78+ # when unit test feedback is available, iterate over test files
10079 for test_file in test_files :
10180 test_cmd = f"python -m commit0 test { repo_path } { test_file } "
102- # set up logging
10381 test_file_name = test_file .replace (".py" , "" ).replace ("/" , "__" )
10482 log_dir = RUN_AIDER_LOG_DIR / "with_tests" / test_file_name
105- log_dir .mkdir (parents = True , exist_ok = True )
106- log_file = log_dir / "run_aider.log"
107-
108- aider_cmd = run_aider (
109- aider_config .llm_name ,
110- target_edit_files ,
111- message_to_aider ,
112- test_cmd ,
113- lint_cmd ,
114- log_dir ,
115- )
11683
117- # write aider command to log file
118- aider_cmd_file = Path (log_dir / "aider_cmd.sh" )
119- aider_cmd_file .write_text (aider_cmd )
120-
121- # write test command to log file
122- test_cmd_file = Path (log_dir / "test_cmd.sh" )
123- test_cmd_file .write_text (test_cmd )
84+ agent .run (
85+ message , test_cmd , lint_cmd , target_edit_files , log_dir ,
86+ )
12487 else :
125- test_cmd = ""
88+ # when unit test feedback is not available, iterate over target files to edit
12689 for f in target_edit_files :
12790 file_name = f .replace (".py" , "" ).replace ("/" , "__" )
12891 log_dir = RUN_AIDER_LOG_DIR / "no_tests" / file_name
129- log_dir .mkdir (parents = True , exist_ok = True )
130- log_file = log_dir / "run_aider.log"
131-
132- aider_cmd = run_aider (
133- aider_config .llm_name ,
134- [f ],
135- message_to_aider ,
136- test_cmd ,
137- lint_cmd ,
138- log_dir ,
92+
93+ agent .run (
94+ message , "" , lint_cmd , [f ], log_dir
13995 )
14096
14197
@@ -146,15 +102,15 @@ def main() -> None:
146102 """
147103 cs = ConfigStore .instance ()
148104 cs .store (name = "user" , node = Commit0Config )
149- cs .store (name = "user" , node = AiderConfig )
105+ cs .store (name = "user" , node = AgentConfig )
150106
151107 hydra .initialize (version_base = None , config_path = "configs" )
152- config = hydra .compose (config_name = "aider " )
108+ config = hydra .compose (config_name = "agent " )
153109
154110 commit0_config = Commit0Config (** config .commit0_config )
155- aider_config = AiderConfig (** config .aider_config )
111+ agent_config = AgentConfig (** config .agent_config )
156112
157- if commit0_config is None or aider_config is None :
113+ if commit0_config is None or agent_config is None :
158114 raise ValueError ("Invalid input" )
159115
160116 dataset = load_dataset (
@@ -173,6 +129,7 @@ def main() -> None:
173129 in SPLIT .get (commit0_config .repo_split , [])
174130 )
175131 ]
132+ assert len (filtered_dataset ) > 0 , "No examples available"
176133
177134 with tqdm (
178135 total = len (filtered_dataset ), smoothing = 0 , desc = "Running Aider for repos"
@@ -181,10 +138,10 @@ def main() -> None:
181138 # Create a future for running Aider for each repo
182139 futures = {
183140 executor .submit (
184- run_aider_for_repo ,
141+ run_agent_for_repo ,
185142 commit0_config ,
186- aider_config ,
187- example if isinstance ( example , dict ) else {},
143+ agent_config ,
144+ example
188145 ): example
189146 for example in filtered_dataset
190147 }
0 commit comments