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: Can start runs from flask
Kilian Lieret640df07e8fb2
diff --git a/sweagent/web/server.py b/sweagent/web/server.pyindex c96bffa2..896d2e90 100644--- a/sweagent/web/server.py+++ b/sweagent/web/server.py@@ -1,48 +1,50 @@import os-from flask import Flask, render_template_string, request+from flask import Flask, render_template, requestimport threadingimport sys++from pytest import skipfrom sweagent import CONFIG_DIR, PACKAGE_DIRfrom sweagent.agent.agents import AgentArgumentsfrom sweagent.agent.models import ModelArgumentsfrom sweagent.environment.swe_env import EnvironmentArguments+from flask_socketio import SocketIO, emit# baaaaaaadsys.path.append(str(PACKAGE_DIR.parent))-from run import ActionsArguments, main, ScriptArguments-+from run import ActionsArguments, ScriptArguments, Main, MainHookapp = Flask(__name__)+socketio = SocketIO(app)-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" value="https://github.com/klieret/swe-agent-test-repo/issues/1" required>- <button type="submit">Run</button>- <input type="checkbox" id="test_run" name="test_run" checked>- <label for="test_run">Test run (no LM queries)</label><br><br>- </form>-</body>-</html>-"""-@app.route('/')def index():- return render_template_string(html_page)+ return render_template("index.html")+[email protected]('connect')+def handle_connect():+ print('Client connected')[email protected]('/run', methods=['POST'])+class WebUpdateRunHook(MainHook):+ def on_start(self):+ print("on start")+ emit('update', {'status': 'started'}, namespace="/run")++ def on_end(self):+ print("on end")+ emit('update', {'status': 'finished'})++ def on_instance_completed(self, *, info, trajectory):+ print("on instance completed")+ emit('update', {'status': 'instance_completed', }, namespace="/run")++[email protected]('/run', methods=['GET'])def run():- data_path = request.form['data_path']- test_run = 'test_run' in request.form+ data_path = request.args.get("data_path", "")+ test_run = 'test_run' in request.argsmodel_name = "gpt4"if test_run:os.environ["SWE_AGENT_EXPERIMENTAL_COMMUNICATE"] = "1"@@ -56,7 +58,7 @@ def run():verbose=True,install_environment=True,),- skip_existing=True,+ skip_existing=False,agent=AgentArguments(model=ModelArguments(model_name=model_name,@@ -69,9 +71,13 @@ def run():),actions=ActionsArguments(open_pr=False, skip_if_commits_reference_issue=True),)- thread = threading.Thread(target=main, args=(defaults,))- thread.start()+ WebUpdateRunHook().on_start()+ # main = Main(defaults)+ # main.add_hook(WebUpdateRunHook())+ # thread = threading.Thread(target=main.main)+ # thread.start()return 'Commands are being executed', 202+if __name__ == "__main__":- app.run(port=5000)\ No newline at end of file+ socketio.run(app, port=5001)\ No newline at end of filediff --git a/sweagent/web/templates/index.html b/sweagent/web/templates/index.htmlnew file mode 100644index 00000000..7e9fedf1--- /dev/null+++ b/sweagent/web/templates/index.html@@ -0,0 +1,43 @@+<!DOCTYPE html>+<html>+<head>+ <title>Run Command</title>+ <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.0/socket.io.js"></script>+ <script>+ document.addEventListener('DOMContentLoaded', function() {+ const socket = io('/run');++ socket.on('update', function(data) {+ console.log("update");+ document.getElementById('update').textContent = data+ });+ });+ </script>+</head>+<body>+ <h1>Start run</h1>+ <form id="dataForm">+ <label for="data_path">Data Path:</label>+ <input type="text" id="data_path" name="data_path" value="https://github.com/klieret/swe-agent-test-repo/issues/1" required>+ <label for="test_run">Test run (no LM queries)</label>+ <input type="checkbox" id="test_run" name="test_run" checked>+ <button type="submit">Run</button>+ </form>+ <div id="responseMessage"></div>+ <div id="update"></div>+ <script>+ document.getElementById('dataForm').addEventListener('submit', function(event) {+ console.log("submit!");+ event.preventDefault();+ var dataPath = document.getElementById('data_path').value;+ var testRun = document.getElementById('test_run').checked;+ fetch(`/run?asdf=true&data_path=${encodeURIComponent(dataPath)}&test_run=${testRun}`, {+ method: 'GET'+ })+ .then(response => response.text())+ .then(text => document.getElementById('responseMessage').innerText = text)+ .catch(error => console.error('Error:', error));+ });+ </script>+</body>+</html>\ No newline at end of file