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]
Fixing most of the frontend
Kilian Lieret71598618ed0e
diff --git a/sweagent/api/server.py b/sweagent/api/server.pyindex 005a5716..44b120d6 100644--- a/sweagent/api/server.py+++ b/sweagent/api/server.py@@ -1,10 +1,7 @@from __future__ import annotations-import atexit-import copyimport jsonimport sys-import tempfileimport timeimport tracebackfrom contextlib import redirect_stderr, redirect_stdout@@ -19,13 +16,10 @@ from flask_cors import CORSfrom flask_socketio import SocketIOfrom sweagent import CONFIG_DIR, PACKAGE_DIR-from sweagent.agent.agents import AgentConfig-from sweagent.agent.models import ModelConfigfrom sweagent.api.hooks import AgentUpdateHook, EnvUpdateHook, MainUpdateHook, WebUpdatefrom sweagent.api.utils import AttrDict, ThreadWithExc-from sweagent.environment.config.deployment import DockerDeploymentConfig-from sweagent.environment.swe_env import EnvironmentConfig-from sweagent.run.run_single import RunSingleActionConfig+from sweagent.environment.config.problem_statement import problem_statement_from_simplified_input+from sweagent.environment.config.repo import repo_from_simplified_input# baaaaaaadsys.path.append(str(PACKAGE_DIR.parent))@@ -98,19 +92,6 @@ def handle_connect():print("Client connected")-def write_env_yaml(data) -> str:- data: Any = AttrDict(copy.deepcopy(dict(data)))- if not data.install_command_active:- data.install = ""- del data.install_command_active- data.pip_packages = [p.strip() for p in data.pip_packages.split("\n") if p.strip()]- path = Path(tempfile.NamedTemporaryFile(delete=False, suffix=".yml").name)- # Make sure that the file is deleted when the program exits- atexit.register(path.unlink)- path.write_text(yaml.dump(dict(data)))- return str(path)--@app.route("/run", methods=["GET", "OPTIONS"])def run():session_id = ensure_session_id_set()@@ -130,46 +111,32 @@ def run():print(run.environment)print(run.environment.base_commit)model_name: str = run.agent.model.model_name- environment_setup = ""- environment_input_type = run.environment.environment_setup.input_type- if environment_input_type == "manual":- environment_setup = str(write_env_yaml(run.environment.environment_setup.manual))- elif environment_input_type == "script_path":- environment_setup = run.environment.environment_setup.script_path["script_path"]- else:- msg = f"Unknown input type: {environment_input_type}"- raise ValueError(msg)- if not environment_setup.strip():- environment_setup = Nonetest_run: bool = run.extra.test_runif test_run:model_name = "instant_empty_submit"- agent_config = OmegaConf.load(CONFIG_DIR / "default_from_url.yaml")- defaults = RunSingleConfig(- suffix="",- environment=EnvironmentConfig(- deployment=DockerDeploymentConfig(),- data_path=run.environment.data_path,- base_commit=run.environment.base_commit,- split="dev",- verbose=True,- install_environment=True,- repo_path=run.environment.repo_path,- environment_setup=environment_setup,- ),- agent=AgentConfig(),- skip_existing=False,- actions=RunSingleActionConfig(),- raise_exceptions=True,+ default_config = yaml.safe_load(Path(CONFIG_DIR / "default_from_url.yaml").read_text())+ config = {+ **default_config,+ "agent": {+ "model": {+ "model_name": model_name,+ },+ },+ "environment": {+ "image_name": run.environment.image_name,+ "script": run.environment.script,+ },+ }+ config["problem_statement"] = problem_statement_from_simplified_input(+ input=run.problem_statement.input,+ type=run.problem_statement.type,)- defaults.agent.model = ModelConfig(- name=model_name,- total_cost_limit=0.0,- per_instance_cost_limit=3.0,- temperature=0.0,- top_p=0.95,+ config["environment"]["repo"] = repo_from_simplified_input(+ input=run.environment.repo_path,+ base_commit=run.environment.base_commit,+ type="auto",)- config = ScriptArguments(**OmegaConf.merge(agent_config, defaults).to_container())+ config = RunSingleConfig.model_validate(**config)thread = MainThread(config, wu)THREADS[session_id] = threadthread.start()diff --git a/sweagent/environment/config/problem_statement.py b/sweagent/environment/config/problem_statement.pyindex f1868f61..cec2830b 100644--- a/sweagent/environment/config/problem_statement.py+++ b/sweagent/environment/config/problem_statement.py@@ -91,3 +91,23 @@ class GithubIssue(BaseModel):ProblemStatementConfig = TextProblemStatement | GithubIssue | EmptyProblemStatement | FileProblemStatement+++def problem_statement_from_simplified_input(+ *, input: str, type: Literal["text", "text_file", "github_issue"]+) -> ProblemStatementConfig:+ """Get a problem statement from a simplified input.++ Args:+ input: Url/path/text+ type: The type of problem statement+ """+ if type == "text":+ return TextProblemStatement(text=input)+ elif type == "text_file":+ return FileProblemStatement(path=Path(input))+ elif type == "github_issue":+ return GithubIssue(url=input)+ else:+ msg = f"Unknown problem statement type: {type}"+ raise ValueError(msg)diff --git a/sweagent/environment/config/repo.py b/sweagent/environment/config/repo.pyindex 3a8e443a..4f203474 100644--- a/sweagent/environment/config/repo.py+++ b/sweagent/environment/config/repo.py@@ -109,3 +109,25 @@ class GithubRepoConfig(BaseModel):RepoConfig = LocalRepoConfig | GithubRepoConfig+++def repo_from_simplified_input(+ *, input: str, base_commit: str = "HEAD", type: Literal["local", "github", "auto"] = "auto"+) -> RepoConfig:+ """Get repo config from a simplified input.++ Args:+ input: Local path or GitHub URL+ type: The type of repo. Set to "auto" to automatically detect the type.+ """+ if type == "local":+ return LocalRepoConfig(path=input, base_commit=base_commit)+ if type == "github":+ return GithubRepoConfig(url=input, base_commit=base_commit)+ if type == "auto":+ if input.startswith("https://github.com/"):+ return GithubRepoConfig(url=input, base_commit=base_commit)+ else:+ return LocalRepoConfig(path=input, base_commit=base_commit)+ msg = f"Unknown repo type: {type}"+ raise ValueError(msg)diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex d8048456..c0a07660 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -21,7 +21,10 @@ class EnvironmentConfig(BaseModel):deployment: DeploymentConfig = Field(default_factory=DockerDeploymentConfig)repo: RepoConfig | None = None+ # fixme: Actually run thesestartup_commands: list[str] = []+ """Execute these commands before starting to run the agent. They will be executed in the same+ shell as the agent."""# pydantic configmodel_config = ConfigDict(extra="forbid")diff --git a/sweagent/frontend/src/Run.js b/sweagent/frontend/src/Run.jsindex d4ec9254..4b815bc5 100644--- a/sweagent/frontend/src/Run.js+++ b/sweagent/frontend/src/Run.js@@ -22,22 +22,16 @@ function Run() {model_name: "gpt4",},},+ problem_statement: {+ type: "",+ input: "",+ },environment: {- data_path: "",- repo_path: "",- base_commit: "",- environment_setup: {- input_type: "manual",- manual: {- python: "3.10",- config_type: "manual",- install: "pip install --editable .",- install_command_active: true,- pip_packages: "",- },- script_path: {- script_path: "",- },+ image_name: "",+ script: "",+ repo: {+ type: "",+ input: "",},},extra: {diff --git a/sweagent/frontend/src/components/controls/LRunControl.js b/sweagent/frontend/src/components/controls/LRunControl.jsindex 06244bd3..fd3d7318 100644--- a/sweagent/frontend/src/components/controls/LRunControl.js+++ b/sweagent/frontend/src/components/controls/LRunControl.js@@ -92,116 +92,43 @@ 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) =>- // setRunConfig(draft => {draft.environment.environment_setup.packages = e.target.value})- // }- // placeholder="/path/to/conda_env.yml"- // />- // </div>- // );- // }- const envInputType = runConfig.environment.environment_setup.input_type;- if (envInputType === "script_path") {- return (- <div>- <div className="input-group mb-3">- <span className="input-group-text">Setup script</span>- <input- type="text"- className="form-control"- onChange={(e) =>- setRunConfig((draft) => {- draft.environment.environment_setup.script_path.script_path =- e.target.value;- })- }- placeholder="/path/to/setup.sh"- defaultValue=""- />- </div>- <div className="alert alert-info" role="alert">- The script will be sourced (every line will be run as if it were- typed into the shell), so make sure there is no exit commands as it- will close the environment.- </div>+ return (+ <div>+ <div className="input-group mb-3">+ <span className="input-group-text">Docker image name</span>+ <input+ type="text"+ className="form-control"+ onChange={(e) =>+ setRunConfig((draft) => {+ draft.environment.image_name = e.target.value;+ })+ }+ placeholder={runConfigDefault.environment.image_name}+ defaultValue=""+ /></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) =>- setRunConfig((draft) => {- draft.environment.environment_setup.manual.python =- e.target.value ||- runConfigDefault.environment.environment_setup.manual- .python;- })- }- placeholder={- runConfigDefault.environment.environment_setup.manual.python- }- defaultValue=""- />- </div>- <div className="input-group mb-3">- <div className="input-group-text">- <input- className="form-check-input mt-0"- type="checkbox"- aria-label="Run installation command"- defaultChecked={true}- onChange={(e) =>- setRunConfig((draft) => {- draft.environment.environment_setup.manual.install_command_active =- e.target.checked;- })- }- />- </div>- <span className="input-group-text">Installation command</span>- <input- type="text"- className="form-control"- aria-label="Text input with checkbox"- placeholder={defaultInstallCommand}- onChange={(e) =>- setRunConfig((draft) => {- draft.environment.environment_setup.manual.install =- e.target.value;- })- }- />- </div>-- <textarea+ <div className="input-group mb-3">+ <span className="input-group-text">Setup script</span>+ <input+ type="text"className="form-control"onChange={(e) =>setRunConfig((draft) => {- draft.environment.environment_setup.manual.pip_packages =- e.target.value;+ draft.environment.script = e.target.value;})}- rows="5"- placeholder="pip installable packages list, one per line (i.e., requirements.txt)."+ placeholder="/path/to/setup.sh"+ defaultValue=""/></div>- );- }+ <div className="alert alert-info" role="alert">+ The script will be sourced (every line will be run as if it were typed+ into the shell), so make sure there is no exit commands as it will+ close the environment.+ </div>+ </div>+ );}function onTabClicked(keyClicked) {@@ -242,7 +169,7 @@ function LRunControl({<inputtype="text"className="form-control"- placeholder="Local repo path or GitHub repo URL. Optional when using GitHub issue as problem source."+ placeholder="Local repo path or GitHub repo URL."onChange={(e) =>setRunConfig((draft) => {draft.environment.repo_path = e.target.value;@@ -280,8 +207,8 @@ function LRunControl({/></div><div className="alert alert-info" role="alert">- Please make sure that you have your API keys configured in- keys.cfg+ See litellm for different models. Please make sure that you have+ your API keys configured in .env.</div></div></Tab>@@ -293,29 +220,6 @@ function LRunControl({here (though SWE-agent will try to figure them out if theyaren'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) =>- setRunConfig((draft) => {- draft.environment.environment_setup.input_type =- e.target.value;- })- }- defaultValue={- runConfigDefault.environment.environment_setup.input_type- }- >- <option value="manual">Python version and packages</option>- <option value="script_path">Path to shell script</option>- {/* Currently broken */}- {/* <option value="conda">Conda environment</option> */}- </select>- </div>{getEnvInput()}</div></Tab>