Skip to content

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]

Enh: Allow to directly specify problem statement (#308)

Kilian Lieretfb39892a7e1b
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index b4a3594d..924bd285 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -58,7 +58,7 @@ class EnvironmentArguments(FrozenSerializable):
"""
# Source of issue statement/problem statement. To run over a batch of issues: Path to a data file
# (`json`, `jsonl`) or directory. To run over single issue: github issue url or path to markdown file
- # with problem statement.
+ # with problem statement or problem statement as text prefixed with `text://`.
data_path: str
image_name: str
split: str = "dev"
diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.py
index a4be13ff..e62fc062 100644
--- a/sweagent/environment/utils.py
+++ b/sweagent/environment/utils.py
@@ -462,21 +462,25 @@ class InstanceBuilder:
self.args["problem_statement_source"] = "online"
def set_problem_statement_from_file(self, file_path: str):
- self.args["problem_statement"] = Path(file_path).read_text()
+ self.set_problem_statement_from_text(Path(file_path).read_text())
+
+ def set_problem_statement_from_text(self, text: str):
+ self.args["problem_statement"] = text
self.args["instance_id"] = hashlib.sha256(self.args["problem_statement"].encode()).hexdigest()[:6]
self.args["problem_statement_source"] = "local"
-
+
def set_problem_statement(self, data_path: str ):
"""Get problem statement for a single instance from a github issue url or a
path to a markdown or text file.
"""
+ if data_path.startswith("text://"):
+ return self.set_problem_statement_from_text(data_path.removeprefix("text://"))
if is_github_issue_url(data_path):
- self.set_problem_statement_from_gh_issue(data_path)
- elif Path(data_path).is_file():
- self.set_problem_statement_from_file(data_path)
- else:
- msg = f"Not sure how to get problem statement from {data_path=}."
- raise ValueError(msg)
+ return self.set_problem_statement_from_gh_issue(data_path)
+ if Path(data_path).is_file():
+ return self.set_problem_statement_from_file(data_path)
+ msg = f"Not sure how to get problem statement from {data_path=}."
+ raise ValueError(msg)
def set_repo_info_from_gh_url(self, url: str, base_commit: Optional[str] = None):
owner, repo = parse_gh_repo_url(url)
@@ -592,7 +596,7 @@ def get_instances(
pass
# The next if statement is very brittle logic to determine if we're processing a single instance
- if (Path(file_path).is_file() and Path(file_path).suffix in ['.md', '.txt']) or is_github_issue_url(file_path):
+ if (Path(file_path).is_file() and Path(file_path).suffix in ['.md', '.txt']) or is_github_issue_url(file_path) or file_path.startswith("text://"):
ib = InstanceBuilder(token=token)
ib.set_problem_statement(file_path)
if repo_path:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 858e65ae..24c72cc4 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -142,6 +142,22 @@ def test_get_instance_gh_issue_gh_repo(tmp_path):
assert instance["version"]
+def test_get_instance_text_issue_gh_repo(tmp_path):
+ instance = get_instances(
+ file_path="text://this is a test",
+ repo_path="https://github.com/princeton-nlp/SWE-agent",
+ )[0]
+ compare_with = {
+ 'repo': "princeton-nlp/SWE-agent",
+ "repo_type": "github",
+ "problem_statement": "this is a test",
+ }
+ for key in compare_with:
+ assert instance[key] == compare_with[key]
+ assert len(instance["base_commit"]) > 10
+ assert instance["version"]
+
+
def test_load_instances(test_data_path, caplog):
test_data_sources = test_data_path / "data_sources"
examples = list(test_data_sources.iterdir())