SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Web: Lay flask scaffolding
Kilian Lieret8275da2c9550
diff --git a/sweagent/__init__.py b/sweagent/__init__.pyindex d5b056e9..34ae313d 100644--- a/sweagent/__init__.py+++ b/sweagent/__init__.py@@ -1,5 +1,6 @@__version__ = "0.2.0"+from pathlib import Pathfrom sweagent.agent.agents import (Agent,AgentArguments,@@ -18,6 +19,11 @@ from sweagent.environment.utils import (get_data_path_name,)+PACKAGE_DIR = Path(__file__).resolve().parent+assert PACKAGE_DIR.is_dir()+CONFIG_DIR = PACKAGE_DIR.parent / "config"+assert CONFIG_DIR.is_dir()+__all__ = ["Agent",@@ -26,4 +32,5 @@ __all__ = ["EnvironmentArguments","SWEEnv","get_data_path_name",+ "PACKAGE_DIR",]diff --git a/sweagent/agent/models.py b/sweagent/agent/models.pyindex cc474189..dc37bb5c 100644--- a/sweagent/agent/models.py+++ b/sweagent/agent/models.py@@ -809,7 +809,7 @@ class InstantEmptySubmitTestModel(BaseModel):MODELS = {"instant_empty_submit": {}}def __init__(self, args: ModelArguments, commands: list[Command]):- """This model immediately submits an empty reproduce.py. Useful for testing purposes"""+ """This model immediately submits. Useful for testing purposes"""super().__init__(args, commands)self._action_idx = 0@@ -849,5 +849,7 @@ def get_model(args: ModelArguments, commands: Optional[list[Command]] = None):return OllamaModel(args, commands)elif args.model_name in TogetherModel.SHORTCUTS:return TogetherModel(args, commands)+ elif args.model_name == "instant_empty_submit":+ return InstantEmptySubmitTestModel(args, commands)else:raise ValueError(f"Invalid model name: {args.model_name}")diff --git a/sweagent/web/server.py b/sweagent/web/server.pynew file mode 100644index 00000000..ed19bfb4--- /dev/null+++ b/sweagent/web/server.py@@ -0,0 +1,78 @@+import os+from flask import Flask, render_template_string, request+import threading+import sys+from sweagent import CONFIG_DIR, PACKAGE_DIR+from sweagent.agent.agents import AgentArguments+from sweagent.agent.models import ModelArguments+from sweagent.environment.swe_env import EnvironmentArguments++# baaaaaaad+sys.path.append(str(PACKAGE_DIR.parent))+from run import ActionsArguments, main, ScriptArguments+++app = Flask(__name__)+++html_page = """+<!DOCTYPE html>+<html>+<head>+ <title>Run Command</title>+</head>+<body>+ <h1>Start run</h1>+ <form action="/run" method="post">+ <label for="data_path">Data Path:</label>+ <input type="text" id="data_path" name="data_path" required>+ <button type="submit">Run</button>+ <input type="checkbox" id="test_run" name="test_run">+ <label for="test_run">Test run (no LM queries)</label><br><br>+ </form>+</body>+</html>+"""++[email protected]('/')+def index():+ return render_template_string(html_page)++[email protected]('/run', methods=['POST'])+def run():+ data_path = request.form['data_path']+ test_run = 'test_run' in request.form+ model_name = "gpt4"+ if test_run:+ os.environ["SWE_AGENT_EXPERIMENTAL_COMMUNICATE"] = "1"+ model_name = "instant_empty_submit"+ defaults = ScriptArguments(+ suffix="",+ environment=EnvironmentArguments(+ image_name="sweagent/swe-agent:latest",+ data_path=data_path,+ split="dev",+ verbose=True,+ install_environment=True,+ ),+ skip_existing=True,+ agent=AgentArguments(+ model=ModelArguments(+ model_name=model_name,+ total_cost_limit=0.0,+ per_instance_cost_limit=3.0,+ temperature=0.0,+ top_p=0.95,+ ),+ config_file=CONFIG_DIR / "default_from_url.yaml",+ ),+ actions=ActionsArguments(open_pr=False, skip_if_commits_reference_issue=True),+ )+ thread = threading.Thread(target=main, args=(defaults,))+ thread.start()+ return 'Commands are being executed', 202++if __name__ == "__main__":+ app.run(port=5000)\ No newline at end of file