Skip to content

Commit 4fa4746

Browse files
committed
update no rich file
1 parent 29b714d commit 4fa4746

File tree

4 files changed

+30
-44
lines changed

4 files changed

+30
-44
lines changed

agent/agents.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ def handle_logging(logging_name: str, log_file: Path) -> None:
2424
class AgentReturn(ABC):
2525
def __init__(self, log_file: Path):
2626
self.log_file = log_file
27+
self.last_cost = 0.0
28+
29+
30+
class Agents(ABC):
31+
def __init__(self, max_iteration: int):
32+
self.max_iteration = max_iteration
33+
34+
@abstractmethod
35+
def run(self) -> AgentReturn:
36+
"""Start agent"""
37+
raise NotImplementedError
38+
39+
40+
class AiderReturn(AgentReturn):
41+
def __init__(self, log_file: Path):
42+
super().__init__(log_file)
2743
self.last_cost = self.get_money_cost()
2844

2945
def get_money_cost(self) -> float:
@@ -40,16 +56,6 @@ def get_money_cost(self) -> float:
4056
return last_cost
4157

4258

43-
class Agents(ABC):
44-
def __init__(self, max_iteration: int):
45-
self.max_iteration = max_iteration
46-
47-
@abstractmethod
48-
def run(self) -> AgentReturn:
49-
"""Start agent"""
50-
raise NotImplementedError
51-
52-
5359
class AiderAgents(Agents):
5460
def __init__(self, max_iteration: int, model_name: str):
5561
super().__init__(max_iteration)
@@ -86,10 +92,6 @@ def run(
8692
level=logging.INFO,
8793
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
8894
)
89-
90-
with open(log_file, "a") as f:
91-
f.write(message)
92-
9395
# Redirect print statements to the log file
9496
sys.stdout = open(log_file, "a")
9597
sys.stderr = open(log_file, "a")
@@ -124,25 +126,11 @@ def run(
124126
else:
125127
coder.run(message)
126128

127-
# #### TMP
128-
129-
# #### TMP
130-
# import time
131-
# import random
132-
133-
# time.sleep(random.random() * 5)
134-
# n = random.random() / 10
135-
# with open(log_file, "a") as f:
136-
# f.write(
137-
# f"> Tokens: 33k sent, 1.3k received. Cost: $0.12 message, ${n} session. \n"
138-
# )
139-
# #### TMP
140-
141129
# Close redirected stdout and stderr
142130
sys.stdout.close()
143131
sys.stderr.close()
144132
# Restore original stdout and stderr
145133
sys.stdout = sys.__stdout__
146134
sys.stderr = sys.__stderr__
147135

148-
return AgentReturn(log_file)
136+
return AiderReturn(log_file)

agent/display.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(self, total_repos: int):
9696
self.start_time_per_repo = {}
9797
self.end_time_per_repo = {}
9898
self.total_time_spent = 0
99+
self.branch_name = ""
99100

100101
self.overall_progress = Progress(
101102
SpinnerColumn(),
@@ -243,6 +244,7 @@ def update_time_display(self, time_in_seconds: int) -> None:
243244

244245
def update_branch_display(self, branch: str) -> None:
245246
"""Update the branch display with the given branch."""
247+
self.branch_name = branch
246248
self.branch_display = Text(f"{branch}", justify="center")
247249
self.layout["info"]["other_info"]["branch"].update(
248250
Panel(self.branch_display, title="Branch", border_style="blue")
@@ -436,7 +438,7 @@ def __exit__(
436438
}
437439

438440
with open(
439-
f"processing_summary_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.json",
441+
f"processing_summary_{self.branch_name}.json",
440442
"w",
441443
) as json_file:
442444
json.dump(summary_data, json_file, indent=4)

agent/run_agent.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ def run_agent_for_repo(
138138
if agent_config.run_tests:
139139
update_queue.put(("start_repo", (repo_name, len(test_files))))
140140
# when unit test feedback is available, iterate over test files
141-
# REMOVE LATER
142-
if agent_config.max_iteration == 10 and repo_name == "simpy":
143-
test_files = test_files[6:]
144141
for test_file in test_files:
145142
update_queue.put(("set_current_file", (repo_name, test_file)))
146143
test_cmd = f"python -m commit0 test {repo_path} {test_file} --branch {branch} --backend {backend} --commit0-config-file {commit0_config_file} --timeout 100"
@@ -257,7 +254,7 @@ def run_agent(
257254
# if len(filtered_dataset) > 1:
258255
# sys.stdout = open(os.devnull, "w")
259256

260-
if agent_config.use_topo_sort_dependencies:
257+
if agent_config.add_import_module_to_context:
261258
# Install Chrome for Playwright for browser-based agents
262259
try:
263260
subprocess.run(["playwright", "install", "chromium"], check=True)

agent/run_agent_no_rich.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datasets import load_dataset
66
from git import Repo
77
from agent.agent_utils import (
8-
args2string,
98
create_branch,
109
get_message,
1110
get_target_edit_files,
@@ -48,10 +47,11 @@ def run_agent_for_repo(
4847
repo_base_dir: str,
4948
agent_config: AgentConfig,
5049
example: RepoInstance,
51-
branch: Optional[str] = None,
50+
branch: str,
5251
override_previous_changes: bool = False,
5352
backend: str = "modal",
5453
log_dir: str = str(RUN_AGENT_LOG_DIR.resolve()),
54+
commit0_config_file: str = "",
5555
) -> None:
5656
"""Run Aider for a given repository."""
5757
# get repo info
@@ -79,8 +79,8 @@ def run_agent_for_repo(
7979
)
8080

8181
# if branch_name is not provided, create a new branch name based on agent_config
82-
if branch is None:
83-
branch = args2string(agent_config)
82+
# if branch is None:
83+
# branch = args2string(agent_config)
8484

8585
# Check if there are changes in the current branch
8686
if local_repo.is_dirty():
@@ -128,23 +128,21 @@ def run_agent_for_repo(
128128
with open(agent_config_log_file, "w") as agent_config_file:
129129
yaml.dump(agent_config, agent_config_file)
130130

131-
# TODO: make this path more general
132-
commit0_config_file = str(Path(repo_path).parent.parent / ".commit0.yaml")
133-
134131
with DirContext(repo_path):
135132
if agent_config is None:
136133
raise ValueError("Invalid input")
137134

138135
if agent_config.run_tests:
139136
# when unit test feedback is available, iterate over test files
140137
for test_file in test_files:
141-
test_cmd = f"python -m commit0 test {repo_path} {test_file} --branch {branch} --backend {backend} --commit0-config-file {commit0_config_file}"
138+
test_cmd = f"python -m commit0 test {repo_path} {test_file} --branch {branch} --backend {backend} --commit0-config-file {commit0_config_file} --timeout 100"
142139
test_file_name = test_file.replace(".py", "").replace("/", "__")
143140
test_log_dir = experiment_log_dir / test_file_name
144141
lint_cmd = get_lint_cmd(
145142
repo_name, agent_config.use_lint_info, commit0_config_file
146143
)
147144
message = get_message(agent_config, repo_path, test_file=test_file)
145+
148146
_ = agent.run(
149147
message,
150148
test_cmd,
@@ -178,7 +176,6 @@ def run_agent_for_repo(
178176
agent_config, repo_path, test_dir=example["test"]["test_dir"]
179177
)
180178
for f in target_edit_files:
181-
dependencies = import_dependencies.get(f, [])
182179
if agent_config.add_import_module_to_context:
183180
dependencies = import_dependencies.get(f, [])
184181
message = update_message_with_dependencies(message, dependencies)
@@ -208,6 +205,7 @@ def run_agent(
208205

209206
agent_config = AgentConfig(**config)
210207

208+
commit0_config_file = os.path.abspath(commit0_config_file)
211209
commit0_config = read_commit0_dot_file(commit0_config_file)
212210

213211
dataset = load_dataset(
@@ -230,7 +228,7 @@ def run_agent(
230228
# if len(filtered_dataset) > 1:
231229
# sys.stdout = open(os.devnull, "w")
232230

233-
if agent_config.use_topo_sort_dependencies:
231+
if agent_config.add_import_module_to_context:
234232
# Install Chrome for Playwright for browser-based agents
235233
try:
236234
subprocess.run(["playwright", "install", "chromium"], check=True)
@@ -258,6 +256,7 @@ def run_agent(
258256
override_previous_changes,
259257
backend,
260258
log_dir,
259+
commit0_config_file,
261260
),
262261
callback=lambda _: pbar.update(
263262
1

0 commit comments

Comments
 (0)