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 feat: Allow to specify python version & req pkgs
Kilian Lieret72f41b4436f5
diff --git a/environment.yml b/environment.ymlindex a7d097f6..77e14e42 100644--- a/environment.yml+++ b/environment.yml@@ -3,4 +3,4 @@ dependencies:- python=3.9- pip- pip:- - -r requirements.txt\ No newline at end of file+ - -r requirements.txtdiff --git a/sweagent/api/server.py b/sweagent/api/server.pyindex 757919b7..3549f8e0 100644--- a/sweagent/api/server.py+++ b/sweagent/api/server.py@@ -7,13 +7,17 @@ except ImportError as e:)raise RuntimeError(msg) from efrom contextlib import redirect_stderr, redirect_stdout+import jsonimport os+from pathlib import Pathimport timeimport traceback-from typing import Dict+from typing import Any, Dictfrom flask import Flask, render_template, request, make_responseimport sys+import yaml+from sweagent import CONFIG_DIR, PACKAGE_DIRfrom sweagent.agent.agents import AgentArgumentsfrom sweagent.agent.models import ModelArguments@@ -25,6 +29,8 @@ from flask_socketio import SocketIOfrom flask_cors import CORSfrom flask import sessionfrom uuid import uuid4+import tempfile+import atexit# baaaaaaadsys.path.append(str(PACKAGE_DIR.parent))@@ -96,6 +102,12 @@ def handle_connect():print('Client connected')+def write_env_yaml(data: Dict[str, Any]) -> str:+ path = Path(tempfile.NamedTemporaryFile(delete=False, suffix=".yml").name)+ atexit.register(path.unlink)+ path.write_text(yaml.dump(data))+ return str(path)+@app.route('/run', methods=['GET', 'OPTIONS'])def run():@@ -113,6 +125,8 @@ def run():data_path = request.args["data_path"]repo_path = request.args["repo_path"]model_name = request.args["model"]+ environment = json.loads(request.args["environment"])+ environment_setup = str(write_env_yaml(environment))test_run = request.args["test_run"].lower() == "true"if test_run:model_name = "instant_empty_submit"@@ -125,6 +139,7 @@ def run():verbose=True,install_environment=True,repo_path=repo_path,+ environment_setup=environment_setup,),skip_existing=False,agent=AgentArguments(diff --git a/sweagent/frontend/src/Run.js b/sweagent/frontend/src/Run.jsindex 0e947131..02dd4015 100644--- a/sweagent/frontend/src/Run.js+++ b/sweagent/frontend/src/Run.js@@ -20,6 +20,8 @@ function Run() {);const [repoPath, setRepoPath] = useState("");const [model, setModel] = useState("gpt4");+ const envConfigDefault = { python: "3.10" };+ const [envConfig, setEnvConfig] = useState(envConfigDefault);const [testRun, setTestRun] = useState(false);const [agentFeed, setAgentFeed] = useState([]);const [envFeed, setEnvFeed] = useState([]);@@ -117,6 +119,7 @@ function Run() {test_run: testRun,repo_path: repoPath,model: model,+ environment: JSON.stringify(envConfig),},});} catch (error) {@@ -256,6 +259,9 @@ function Run() {setModel={setModel}tabKey={tabKey}setTabKey={setTabKey}+ envConfig={envConfig}+ setEnvConfig={setEnvConfig}+ envConfigDefault={envConfigDefault}/><div id="demo"><hr />diff --git a/sweagent/frontend/src/components/controls/LRunControl.js b/sweagent/frontend/src/components/controls/LRunControl.jsindex 9cbd1c2f..822e2a09 100644--- a/sweagent/frontend/src/components/controls/LRunControl.js+++ b/sweagent/frontend/src/components/controls/LRunControl.js@@ -18,8 +18,13 @@ function LRunControl({setModel,tabKey,setTabKey,+ envConfig,+ setEnvConfig,+ envConfigDefault,}) {+ // ps = problem statementconst [psType, setPsType] = useState("gh");+ const [envInputType, setEnvInputType] = useState("manual");const defaultPS ="https://github.com/marshmallow-code/marshmallow/issues/1359";@@ -30,6 +35,8 @@ function LRunControl({};function getPsInput() {+ // Problem statement input controls based on the value of the problem statement type+ // dropdown menu.if (psType === "gh") {return (<div className="input-group mb-3">@@ -70,8 +77,73 @@ function LRunControl({}}+ function getEnvInput() {+ // Get environment configuration input controls based on the+ // "Environment type" dropdown menu.+ if (envInputType === "conda") {+ return (+ <div className="input-group mb-3">+ <span className="input-group-text">Conda environment</span>+ <input+ type="text"+ className="form-control"+ onChange={(e) =>+ setEnvConfig({ ...envConfig, packages: e.target.value })+ }+ placeholder="/path/to/conda_env.yml"+ />+ </div>+ );+ }+ if (envInputType === "manual") {+ return (+ <div>+ <div className="input-group mb-3">+ <span className="input-group-text">Python version</span>+ <input+ type="text"+ className="form-control"+ onChange={(e) =>+ setEnvConfig({+ ...envConfig,+ python: e.target.value || envConfigDefault["python"],+ })+ }+ placeholder={envConfigDefault["python"]}+ />+ </div>+ <textarea+ className="form-control"+ onChange={(e) =>+ setEnvConfig({ ...envConfig, pip_packages: e.target.value })+ }+ rows="5"+ placeholder="pip installable packages list, one per line (i.e., requirements.txt). You can also just enter . to install the package with pip install ."+ />+ </div>+ );+ }+ }++ function handleEnvInputTypeUpdate(value) {+ // Handle a change in how the user wants to configure the environment.+ // We need to make sure that we clear out config items that aren't "active" anymore+ // For example, if we switch from conda to manual, we should clear out conda env path+ setEnvInputType(value);+ if (value === "conda") {+ setEnvConfig({ packages: "", config_type: "conda" });+ } else if (value === "manual") {+ setEnvConfig({+ python: envConfigDefault["python"],+ config_type: "manual",+ });+ }+ }+function onTabClicked(keyClicked) {+ /* Handle clicks on the tabs of the control/setting groups */if (keyClicked === tabKey) {+ // Clicking the active tab hides itsetTabKey(null);} else {setTabKey(keyClicked);@@ -130,6 +202,32 @@ function LRunControl({</div></div></Tab>+ <Tab eventKey="env" title="Environment">+ <div className="p-3">+ <p>+ These settings set up the environment in which SWE-agent operates.+ It's a good idea to explicitly specify all relevant setup commands+ here (though SWE-agent will try to figure them out if they+ aren't).+ </p>+ <div className="input-group mb-3">+ <span className="input-group-text">+ Environment specification+ </span>+ <select+ className="form-select"+ aria-label="Select problem statement type"+ onChange={(e) => handleEnvInputTypeUpdate(e.target.value)}+ value={envInputType}+ >+ <option value="manual">Python version and packages</option>+ {/* Currently broken */}+ {/* <option value="conda">Conda environment</option> */}+ </select>+ </div>+ {getEnvInput()}+ </div>+ </Tab><Tab eventKey="settings" title="Extra Settings"><div className="p-3"><Form.Check