Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions agent/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import os
from abc import ABC, abstractmethod
from pathlib import Path
import logging

from aider.coders import Coder
from aider.models import Model
from aider.io import InputOutput
from tenacity import retry, wait_exponential


class Agents(ABC):
Expand All @@ -23,6 +25,9 @@ def __init__(self, max_iteration: int, model_name: str):
super().__init__(max_iteration)
self.model = Model(model_name)

@retry(
wait=wait_exponential(multiplier=1, min=4, max=10),
)
def run(
self,
message: str,
Expand All @@ -44,10 +49,33 @@ def run(
log_dir.mkdir(parents=True, exist_ok=True)
input_history_file = log_dir / ".aider.input.history"
chat_history_file = log_dir / ".aider.chat.history.md"

print(
f"check {os.path.abspath(chat_history_file)} for prompts and lm generations",
file=sys.stderr,
)
# Set up logging
log_file = log_dir / "aider.log"
logging.basicConfig(
filename=log_file,
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)

# Redirect print statements to the log file
sys.stdout = open(log_file, "a")
sys.stderr = open(log_file, "a")

# Configure httpx logging
httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.INFO)
httpx_logger.propagate = False # Prevent propagation to root logger
httpx_handler = logging.FileHandler(log_file)
httpx_handler.setFormatter(
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
)
httpx_logger.addHandler(httpx_handler)

io = InputOutput(
yes=True,
input_history_file=input_history_file,
Expand All @@ -64,4 +92,13 @@ def run(
)
coder.max_reflection = self.max_iteration
coder.stream = False

# Run the agent
coder.run(message)

# Close redirected stdout and stderr
sys.stdout.close()
sys.stderr.close()
# Restore original stdout and stderr
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
2 changes: 1 addition & 1 deletion agent/run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def run_agent(agent_config_file: str) -> None:
with tqdm(
total=len(filtered_dataset), smoothing=0, desc="Running Aider for repos"
) as pbar:
with multiprocessing.Pool(processes=10) as pool:
with multiprocessing.Pool(processes=2) as pool:
results = []

# Use apply_async to submit jobs and add progress bar updates
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"aider-chat>=0.56.0",
"modal>=0.64.95",
"typer>=0.12.0",
"tenacity>=8.5.0",
"datasets>=3.0.0",
"docker>=7.1.0",
"fastcore>=1.7.8",
Expand Down
11 changes: 11 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.