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]
fix: allow token from keys.cfg to get passed to ghapi (#31)
Tyler Coyner4e77b2258535
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex fbb14157..9b256993 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -83,11 +83,6 @@ class SWEEnv(gym.Env):logger.warning("Failed to get commit hash for this repo")self.commit_sha = None- # Load Task Instances- self.data_path = self.args.data_path- self.data = get_instances(self.data_path, self.args.base_commit, self.args.split)- self.logger.info(f"💽 Loaded dataset from {self.data_path}")-# Set GitHub Tokenself.token = os.environ.get("GITHUB_TOKEN", None)if (self.token is None or self.token == "") and os.path.isfile(@@ -96,6 +91,11 @@ class SWEEnv(gym.Env):self.cfg = config.Config(os.path.join(os.getcwd(), "keys.cfg"))self.token = self.cfg.get("GITHUB_TOKEN", "git")+ # Load Task Instances+ self.data_path = self.args.data_path+ self.data = get_instances(self.data_path, self.args.base_commit, self.args.split, token=self.token)+ self.logger.info(f"💽 Loaded dataset from {self.data_path}")+# Establish connection with execution containerself.image_name = args.image_nameself._reset_container()@@ -642,7 +642,7 @@ class SWEEnv(gym.Env):passelse:raise ValueError(f"Invalid command type: {command['type']}")-+def interrupt(self):"""Send interrupt signal to container and exhaust stdout buffer with a communicate calldiff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex c3efc655..8d922893 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -48,7 +48,7 @@ def copy_file_to_container(container, contents, container_path):- container: Docker SDK container object.- contents: The string to copy into the container.- container_path: The path inside the container where the string should be copied to.-+Returns:- None"""@@ -126,7 +126,7 @@ def read_with_timeout(container, pid_func, timeout_duration):if time.time() >= end_time:raise TimeoutError("Timeout reached while reading from subprocess.\nCurrent buffer: {}\nRunning PIDs: {}".format(buffer.decode(), pids))return buffer.decode()-+class timeout:def __init__(self, seconds=TIMEOUT_DURATION, error_message="Timeout"):@@ -231,7 +231,7 @@ def _get_persistent_container(ctr_name: str, image_name: str, persistent: bool =stdout=PIPE,stderr=STDOUT,text=True,- bufsize=1, # line buffered+ bufsize=1, # line buffered)time.sleep(START_UP_DELAY)# try to read output from container setup (usually an error), timeout if no output@@ -279,7 +279,7 @@ def get_commit(api: GhApi, owner: str, repo: str, base_commit: str = None):-def get_instances(file_path: str, base_commit: str = None, split: str = None):+def get_instances(file_path: str, base_commit: str = None, split: str = None, token: str = None):"""Getter function for handling json, jsonl files@@ -295,7 +295,7 @@ def get_instances(file_path: str, base_commit: str = None, split: str = None):# If file_path is a github issue url, fetch the issue and return a single instanceif is_from_github_url(file_path):match = GITHUB_ISSUE_URL_PATTERN.search(file_path)- api = GhApi()+ api = GhApi(token=token)if match:owner, repo, issue_number = match.groups()record = dict()@@ -317,7 +317,7 @@ def get_instances(file_path: str, base_commit: str = None, split: str = None):return json.load(open(file_path))if file_path.endswith(".jsonl"):return [json.loads(x) for x in open(file_path, 'r').readlines()]-+# Attempt load from HF datasets as a last resorttry:return load_dataset(file_path, split=split)@@ -325,4 +325,4 @@ def get_instances(file_path: str, base_commit: str = None, split: str = None):raise ValueError(f"Could not load instances from {file_path}. ""Please ensure --data_path is a GitHub URL, a SWE-bench HuggingFace dataset, or a JSON/JSONL file."- )\ No newline at end of file+ )