update: SWE Agent

This commit is contained in:
seeker 2024-07-03 20:11:32 +08:00
parent 92f94862cb
commit fafe2ce68f
8 changed files with 103 additions and 91 deletions

View file

@ -122,6 +122,8 @@ class Browser:
async def goto(self, url: str, timeout: float = 30000):
"""Navigate to a specific URL."""
if self.page is None:
await self.start()
async with self.reporter as reporter:
await reporter.async_report(url, "url")
await self.page.goto(url, timeout=timeout)

View file

@ -2,7 +2,7 @@ import subprocess
import threading
from queue import Queue
from metagpt.const import SWE_SETUP_PATH
from metagpt.const import SWE_SETUP_PATH, SWE_WORKSPACE_ROOT
from metagpt.tools.tool_registry import register_tool
from metagpt.utils.report import END_MARKER_VALUE, TerminalReporter
@ -136,13 +136,14 @@ class Terminal:
class Bash(Terminal):
"""
A class to run bash commands directly and provides custom shell functions.
All custom functions in this class can ONLY be called via the `Bash.run` method.
"""
def __init__(self):
"""init"""
super().__init__()
setup_cmd = f"source {SWE_SETUP_PATH}"
self.run_command(setup_cmd)
self.run_command(f"cd {SWE_WORKSPACE_ROOT} && {setup_cmd}")
def run(self, cmd) -> str:
"""
@ -184,7 +185,7 @@ class Bash(Terminal):
filename (str): The name of the file to create.
- submit
Submits your current code and terminates the session.
Submits your current code. it can only be executed once, the last action before the `end`.
- search_dir_and_preview <search_term> [<dir>]
Searches for search_term in all files in dir and gives their code preview

View file

@ -177,7 +177,7 @@ create() {
# @yaml
# signature: submit
# docstring: submits your current code and terminates the session. this is the only submit action needed; no need to run git add or git commit before this.
# docstring: submits your current code. the last action before the `end`, it can only be executed once.
submit() {
# Check if the patch file exists and is non-empty
if [ -s "$SWE_CMD_WORK_DIR/test.patch" ]; then
@ -186,8 +186,7 @@ submit() {
fi
git add -A
git diff --cached > model.patch
echo "<<SUBMISSION||"
cat model.patch
echo "||SUBMISSION>>"
echo "<<SUBMISSION START||"
git diff --cached
echo "||SUBMISSION DONE>>"
}

View file

@ -16,10 +16,12 @@ def extract_patch(command_output):
def load_hf_dataset(dataset_name_or_path: str, cache_dir, split: str = "test", existing_ids: list = []):
if Path(dataset_name_or_path).exists():
dataset = load_from_disk(dataset_name_or_path)
data_dir = cache_dir / dataset_name_or_path
if Path(data_dir).exists():
dataset = load_from_disk(data_dir)
else:
dataset = load_dataset(dataset_name_or_path, cache_dir=cache_dir)
dataset = load_dataset(dataset_name_or_path)
dataset.save_to_disk(data_dir)
print(dataset)
if split not in dataset:
raise ValueError(f"Invalid split {split} for dataset {dataset_name_or_path}")