update: SWE Agent

This commit is contained in:
seeker 2024-07-04 16:07:22 +08:00
parent 5c0f490c04
commit 816a6eadde
5 changed files with 36 additions and 30 deletions

View file

@ -5,7 +5,7 @@ from datetime import datetime
from metagpt.config2 import config
from metagpt.const import DEFAULT_WORKSPACE_ROOT, METAGPT_ROOT
from metagpt.logs import logger
from metagpt.roles.di.swe import SWE
from metagpt.roles.di.swe_agent import SWEAgent
from metagpt.tools.libs.terminal import Terminal
from metagpt.tools.swe_agent_commands.swe_agent_utils import load_hf_dataset
@ -74,13 +74,14 @@ async def run(instance, swe_result_dir):
)
logger.info(f"**** Starting to run {instance['instance_id']}****")
swe_agent = SWE()
swe_agent = SWEAgent()
swe_agent.run_eval = True
await swe_agent.run(user_requirement_and_issue)
save_predictions(swe_agent, instance, swe_result_dir)
logger.info(f"**** Finished running {instance['instance_id']}****")
def save_predictions(swe_agent: SWE, instance, swe_result_dir):
def save_predictions(swe_agent: SWEAgent, instance, swe_result_dir):
output_file = swe_result_dir / "all_preds.jsonl"
instance["model_name_or_path"] = swe_agent.config.llm.model
instance["model_patch"] = swe_agent.output_diff

View file

@ -1,41 +1,44 @@
import asyncio
from metagpt.logs import logger
from metagpt.roles.di.swe import SWE
from metagpt.roles.di.swe_agent import SWEAgent
FIX_ISSUE1 = """
Write a fix for this issue: https://github.com/langchain-ai/langchain/issues/20453,
you can fix it on this repo https://github.com/garylin2099/langchain,
you can fix it on this repo https://github.com/garylin2099/langchain
"""
# + "checkout a branch named test-fix, commit your changes, push, and create a PR to the master branch of https://github.com/iorisa/langchain"
# + "checkout a branch named test-fix, commit your changes, push,
# and create a PR to the master branch of https://github.com/iorisa/langchain"
# """
FIX_ISSUE2 = """
Write a fix for this issue https://github.com/geekan/MetaGPT/issues/1275.
You can fix it on the v0.8-release branch of this repo https://github.com/garylin2099/MetaGPT,
You can fix it on the v0.8-release branch of this repo https://github.com/garylin2099/MetaGPT
"""
# + "during fixing, checkout a branch named test-fix-1275, commit your changes, push, and create a PR to the v0.8-release branch of https://github.com/garylin2099/MetaGPT"
# + "during fixing, checkout a branch named test-fix-1275, commit your changes, push,
# and create a PR to the v0.8-release branch of https://github.com/garylin2099/MetaGPT"
FIX_ISSUE3 = """
Write a fix for this issue https://github.com/geekan/MetaGPT/issues/1262.
You can fix it on this repo https://github.com/garylin2099/MetaGPT,
during fixing, checkout a branch named test-fix-1262, commit your changes, push, and create a PR to https://github.com/garylin2099/MetaGPT
You can fix it on this repo https://github.com/garylin2099/MetaGPT
"""
# during fixing, checkout a branch named test-fix-1262, commit your changes, push,
# and create a PR to https://github.com/garylin2099/MetaGPT
# """
FIX_ISSUE_SIMPLE = """
Write a fix for this issue: https://github.com/mannaandpoem/simple_calculator/issues/1,
you can fix it on this repo https://github.com/garylin2099/simple_calculator,
checkout a branch named test, commit your changes, push, and create a PR to the master branch of original repo.
you can fix it on this repo https://github.com/garylin2099/simple_calculator
"""
# checkout a branch named test, commit your changes, push, and create a PR to the master branch of original repo.
# """
NO_ENV_TIP = """
Because the environment is not available, you DO NOT need to run and modify any existing test case files or
add new test case files to ensure that the bug is fixed.
"""
if __name__ == "__main__":
swe_agent = SWE()
swe_agent = SWEAgent()
logger.info("**** Starting run ****")
user_requirement_and_issue = (
# FIX_ISSUE1
# FIX_ISSUE2
# FIX_ISSUE3
FIX_ISSUE_SIMPLE
+ """Because the environment is not available, you DO NOT need to run and modify any existing test case files or add new test case files to ensure that the bug is fixed."""
)
user_requirement_and_issue = FIX_ISSUE1 + NO_ENV_TIP
asyncio.run(swe_agent.run(user_requirement_and_issue))
logger.info("**** Finished running ****")
logger.info(f"Patch: {swe_agent.output_diff}")