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]
Some more ruff checks
Kilian Lieret930515ba5756
diff --git a/docs/dev/contribute.md b/docs/dev/contribute.mdindex 8bce1ed0..01df9cfa 100644--- a/docs/dev/contribute.md+++ b/docs/dev/contribute.md@@ -25,11 +25,15 @@ pre-commit install`pre-commit` will check for formatting and basic syntax errors before your commits.-Some issues can be automatically fixed with [`ruff`](https://github.com/charliermarsh/ruff) (part of the checks):+!!! tip "Autofixes"+ Most problems (including formatting) will be automatically fixed.+ Therefore, if `pre-commit`/`git commit` fails on its first run, simply try running it a second time.-```bash-pipx run ruff check --fix-```+ Some more autofixes can be enabled with the `--unsafe-fixes` option from [`ruff`](https://github.com/charliermarsh/ruff):++ ```bash+ pipx run ruff check --fix --unsafe-fixes+ ```## Running testsdiff --git a/inspector/server.py b/inspector/server.pyindex d59b1e53..a83bae3b 100644--- a/inspector/server.py+++ b/inspector/server.py@@ -153,7 +153,7 @@ def load_content(file_name, gold_patches, test_patches) -> dict[str, Any]:content = append_exit(content) # accommodate new and old formatcontent = append_patch(Path(file_name).stem, content, gold_patches, "Gold")content = append_patch(Path(file_name).stem, content, test_patches, "Test")- content = append_results(+ return append_results(Path(file_name),Path(file_name).stem,content,@@ -162,7 +162,6 @@ def load_content(file_name, gold_patches, test_patches) -> dict[str, Any]:scorecards,scorecards_file,)- return contentdef load_results(results_path: Path) -> dict[str, Any] | None:diff --git a/inspector/static.py b/inspector/static.pyindex 236a6ecb..10132484 100644--- a/inspector/static.py+++ b/inspector/static.py@@ -146,8 +146,7 @@ def find_relative_path(from_path, to_path):to_target = to_path.parts[common_parts:]# Combine to get the relative path- relative_path = Path(*back_to_ancestor, *to_target)- return relative_path+ return Path(*back_to_ancestor, *to_target)def save_all_trajectories(directory):diff --git a/pyproject.toml b/pyproject.tomlindex 69d44063..f188d547 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -117,8 +117,10 @@ target-version = "py39"# McCabe complexity (`C901`) by default.# I001: Isort, I002: required importselect = [- "E999",- "E902",+ # Error (E)+ "E",+ # Error (PLE)+ "PLE",# pycodestyle"E713", # not in"E714", # is not@@ -147,8 +149,26 @@ select = ["B007", # unused loop var# flake8-errmsg"EM",+ # flake8-implicit-str-concat+ "ISC001",+ # flake8-future-annotations+ "FA102",+ # flake8-return+ "RET",+ # RUF+ "RUF019", # unneded key in dict check+]+ignore = [+ # flake8-return+ "RET505", # can't autofix+ "RET506", # can't autofix+ "RET507", # can't autofix+ # error (E)+ "E501", # line too long+ "E402", # import not on top of file+ "E722", # bare except+ "E741", # ambiguous symbol]-ignore = []# Allow fix for all enabled rules (when `--fix`) is provided.fixable = ["ALL"]diff --git a/run.py b/run.pyindex f66d2f20..a21ae63c 100644--- a/run.py+++ b/run.py@@ -233,7 +233,7 @@ class SaveApplyPatchHook(MainHook):patch_output_file = patch_output_dir / f"{instance_id}.patch"if not info.get("submission"):logger.info("No patch to save.")- return+ return Nonemodel_patch = info["submission"]patch_output_file.write_text(model_patch)if self._is_promising_patch(info):diff --git a/sweagent/agent/commands.py b/sweagent/agent/commands.pyindex 244d2c6a..67399566 100644--- a/sweagent/agent/commands.py+++ b/sweagent/agent/commands.py@@ -160,7 +160,7 @@ class ParseCommandBash(ParseCommand):if len(matches) == 0:return []elif len(matches) > 1:- msg = "Non-shell file contains multiple @yaml tags.\n" "Only one @yaml tag is allowed per script."+ msg = "Non-shell file contains multiple @yaml tags.\nOnly one @yaml tag is allowed per script."raise ValueError(msg)else:yaml_content = matches[0]diff --git a/sweagent/agent/history_processors.py b/sweagent/agent/history_processors.pyindex e5c935ba..1848b771 100644--- a/sweagent/agent/history_processors.py+++ b/sweagent/agent/history_processors.py@@ -124,5 +124,4 @@ class ClosedWindowHistoryProcessor(HistoryProcessor):)windows.add(file)new_history.append(data)- history = list(reversed(new_history))- return history+ return list(reversed(new_history))diff --git a/sweagent/agent/models.py b/sweagent/agent/models.pyindex b022d871..783db4d2 100644--- a/sweagent/agent/models.py+++ b/sweagent/agent/models.py@@ -551,8 +551,7 @@ def anthropic_query(model: AnthropicModel | BedrockModel, history: list[dict[str# Calculate + update costs, return responsemodel.update_stats(response.usage.input_tokens, response.usage.output_tokens)- response = "\n".join([x.text for x in response.content])- return response+ return "\n".join([x.text for x in response.content])class OllamaModel(BaseModel):@@ -675,8 +674,7 @@ class TogetherModel(BaseModel):mapping = {"user": "human", "assistant": "bot", "system": "bot"}prompt = [f'<{mapping[d["role"]]}>: {d["content"]}' for d in history]prompt = "\n".join(prompt)- prompt = f"{prompt}\n<bot>:"- return prompt+ return f"{prompt}\n<bot>:"@retry(wait=wait_random_exponential(min=1, max=15),