Skip to content

Commit fb27d3d

Browse files
committed
aider update message to aider logic
1 parent 51e0968 commit fb27d3d

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

baselines/baseline_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ def get_prompt(file_list: str) -> str:
125125

126126

127127
def find_files_with_error(target_dir: str) -> List[str]:
128-
"""Find the files with the error 'NotImplementedError('IMPLEMENT ME HERE')'."""
128+
"""Find the files with the error 'NotImplementedError('IMPLEMENT ME
129+
HERE')'.
130+
"""
129131
# The grep command
130132
command = f"grep -R -l \"NotImplementedError('IMPLEMENT ME HERE')\" {target_dir}"
131133

baselines/run_aider.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from pathlib import Path
66

77
import hydra
8+
from datasets import load_dataset
9+
from omegaconf import OmegaConf
10+
from tqdm.contrib.concurrent import thread_map
11+
812
from baselines.baseline_utils import (
913
PROMPT_HEADER,
1014
REFERENCE_HEADER,
@@ -16,9 +20,6 @@
1620
get_reference,
1721
)
1822
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
2223

2324
# from aider.run_aider import get_aider_cmd
2425

@@ -30,23 +31,12 @@
3031

3132
def get_aider_cmd(
3233
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,
3836
test_cmd: str,
3937
) -> str:
4038
"""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"
5040

5141
return aider_cmd
5242

@@ -57,54 +47,54 @@ def run_aider_for_repo(
5747
ds: dict,
5848
) -> None:
5949
"""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:
6151
raise ValueError("Invalid input")
6252

6353
# get repo info
6454
_, repo_name = ds["repo"].split("/")
6555

66-
# TODO: assuming we have all test_files
56+
# TODO: assuming we have all test_files, which we currently do not have
6757
test_files = ds["test_files"]
6858

6959
repo_path = os.path.join(commit0_config.base_dir, repo_name)
7060
target_edit_files = find_files_with_error(repo_path)
7161

7262
target_edit_files_cmd_args = " ".join(target_edit_files)
7363

74-
prompt = get_prompt(target_edit_files_cmd_args)
64+
prompt = f"{PROMPT_HEADER} " + get_prompt(target_edit_files_cmd_args)
7565

7666
# support context for aider
7767
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(
7969
dir_path=Path(os.path.join(repo_path, ds["test"]["test_dir"])),
8070
prefix="",
8171
include_stubs=True,
8272
)
8373
else:
8474
unit_tests_info = ""
8575

76+
# TODO: assuming we have specification, which we currently do not have
8677
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"])
8879
else:
8980
reference = ""
9081

9182
if aider_config.use_repo_info:
92-
repo_info = get_dir_info(
83+
repo_info = f"\n{REPO_INFO_HEADER} " + get_dir_info(
9384
dir_path=Path(repo_path), prefix="", max_depth=2, include_stubs=False
9485
)
9586
else:
9687
repo_info = ""
9788

89+
message_to_aider = prompt + reference + repo_info + unit_tests_info
90+
9891
for test_file in test_files:
9992
test_cmd = f"python -m commit0.harness.run_pytest_ids --repo {repo_name} --test_ids {test_file} --branch_name aider"
10093

10194
aider_cmd = get_aider_cmd(
10295
aider_config.llm_name,
10396
target_edit_files_cmd_args,
104-
prompt,
105-
reference,
106-
repo_info,
107-
unit_tests_info,
97+
message_to_aider,
10898
test_cmd,
10999
)
110100

@@ -128,7 +118,10 @@ def run_aider_for_repo(
128118

129119
@hydra.main(version_base=None, config_path="config", config_name="aider")
130120
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+
"""
132125
config = BaselineConfig(config=OmegaConf.to_object(config))
133126
commit0_config = config.commit0_config
134127
aider_config = config.aider_config

0 commit comments

Comments
 (0)