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]
Rename is_from_github_url and minor typing fixes
Kilian Lieret1914000cca47
diff --git a/run_replay.py b/run_replay.pyindex 09a1d659..1cb576d0 100644--- a/run_replay.py+++ b/run_replay.py@@ -5,7 +5,7 @@ import osimport yamlfrom argparse import ArgumentParser-from sweagent.environment.utils import is_from_github_url+from sweagent.environment.utils import is_github_issue_urlfrom typing import Any, Dict, Listimport run as runscript@@ -71,7 +71,7 @@ def process_single_traj(traj_path: str, config_file: str, data_path: str, suffixreplay_task_instances_path = create_task_instances_tmp_file([json.loads(x) for x in open(data_path, "r").readlines()])elif data_path.endswith(".json"):replay_task_instances_path = create_task_instances_tmp_file(json.load(open(data_path)))- elif is_from_github_url(data_path):+ elif is_github_issue_url(data_path):is_github = Truereplay_task_instances_path = data_pathelse:diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex 52ad8365..ae4fd538 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -24,7 +24,7 @@ from sweagent.environment.utils import (get_container,get_gh_issue_data,get_instances,- is_from_github_url,+ is_github_issue_url,parse_gh_issue_url,parse_gh_repo_url,read_with_timeout,@@ -84,7 +84,7 @@ class SWEEnv(gym.Env):self.logger = loggerself.persistent = args.container_name is not Noneself.returncode = None- self.is_from_github_url = is_from_github_url(args.data_path)+ self.is_from_github_url = is_github_issue_url(args.data_path)if not self.args.verbose:self.logger.disabled = True@@ -108,6 +108,8 @@ class SWEEnv(gym.Env):# Load Task Instancesself.data_path = self.args.data_pathself.data = get_instances(self.data_path, self.args.base_commit, self.args.split, token=self._github_token)+ #: Instance we're currently processing. Gets set in self.reset.+ self.record = Noneself.logger.info(f"💽 Loaded dataset from {self.data_path}")# Establish connection with execution container@@ -119,7 +121,7 @@ class SWEEnv(gym.Env):self.idx = 0self.clean_multi_line_functions = lambda x: x- def reset(self, index: int = None, apply_test_patch: bool = False) -> Tuple[str, dict]:+ def reset(self, index: Optional[int] = None, apply_test_patch: bool = False) -> Tuple[str, dict]:"""Function to reset container between each task instance.* Clones instance's repositorydiff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex b1582a64..ed731654 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -17,7 +17,7 @@ from ghapi.all import GhApifrom io import BytesIOfrom pathlib import Pathfrom subprocess import PIPE, STDOUT-from typing import List, Set, Tuple, Dict+from typing import List, Optional, Set, Tuple, DictLOGGER_NAME = "intercode"START_UP_DELAY = 5@@ -37,7 +37,7 @@ def get_data_path_name(data_path: str):return Path(data_path).stem-def is_from_github_url(data_path: str):+def is_github_issue_url(data_path: str):return GITHUB_ISSUE_URL_PATTERN.search(data_path) is not None@@ -347,7 +347,7 @@ def get_gh_issue_data(issue_url: str, *, token: str = ""):return api.issues.get(owner, repo, issue_number)-def get_instances(file_path: str, base_commit: str = None, split: str = None, token: str = None):+def get_instances(file_path: str, base_commit: Optional[str] = None, split: Optional[str] = None, token: Optional[str] = None):"""Getter function for handling json, jsonl files@@ -364,7 +364,7 @@ def get_instances(file_path: str, base_commit: str = None, split: str = None, toreturn dataset_or_dict# If file_path is a github issue url, fetch the issue and return a single instance- if is_from_github_url(file_path):+ if is_github_issue_url(file_path):try:owner, repo, issue_number = parse_gh_issue_url(file_path)except InvalidGithubURL:@@ -457,4 +457,4 @@ def format_trajectory_markdown(trajectory: List[Dict[str, str]]):"","</details>",]- return "\n".join(prefix) + "\n\n---\n\n".join(steps) + "\n".join(suffix)+ return "\n".join(prefix) + "\n\n---\n\n".join(steps) + "\n".join(suffix)\ No newline at end of filediff --git a/tests/test_utils.py b/tests/test_utils.pyindex 19d79c5d..cbc55c61 100644--- a/tests/test_utils.py+++ b/tests/test_utils.py@@ -1,4 +1,4 @@-from sweagent.environment.utils import format_trajectory_markdown, _MARKDOWN_TRAJECTORY_EMOJI_MAPPING, remove_triple_backticks, parse_gh_repo_url, parse_gh_issue_url, is_from_github_url, get_associated_commit_urls+from sweagent.environment.utils import format_trajectory_markdown, _MARKDOWN_TRAJECTORY_EMOJI_MAPPING, remove_triple_backticks, parse_gh_repo_url, parse_gh_issue_url, is_github_issue_url, get_associated_commit_urlsdef test_format_trajectory_markdown(test_trajectory):formatted = format_trajectory_markdown(test_trajectory["trajectory"])@@ -28,8 +28,8 @@ def test_parse_gh_issue_url():def test_is_from_github_url():- assert not is_from_github_url("")- assert is_from_github_url("https://github.com/princeton-nlp/SWE-agent/issues/43")+ assert not is_github_issue_url("")+ assert is_github_issue_url("https://github.com/princeton-nlp/SWE-agent/issues/43")def test_get_associated_commit_urls():