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 run_replay with github URLs as data_path (#58)
Kilian Lieret09da9963fbb7
diff --git a/run_replay.py b/run_replay.pyindex b4d02f90..3e01cdbb 100644--- a/run_replay.py+++ b/run_replay.py@@ -1,10 +1,13 @@import jsonimport osimport subprocess+from typing import Any, Dict, Listimport yamlfrom argparse import ArgumentParser+from sweagent.environment.utils import is_from_github_url+def process_synthetic_trajs(action_trajs_path: str, config_file: str, suffix: str):# Load action trajectories, task instances@@ -69,7 +72,6 @@ def process_single_traj(traj_path: str, config_file: str, data_path: str, suffixend="\n",flush=True)- replay_task_instances_path = instance_id + ".jsonl"# Get data_path from args.yamlif data_path is None:@@ -81,18 +83,29 @@ def process_single_traj(traj_path: str, config_file: str, data_path: str, suffixdata_path = args['environment']['data_path']# Identify the relevant task instance and create it- data = None++ def create_task_instances_tmp_file(data: List[Dict[str, Any]]) -> str:+ """Helper function to create a temporary file to write task instances to.+ Returns path to the temporary file.+ """+ data = [d for d in data if d["instance_id"] == instance_id]+ tmp_path = instance_id + ".jsonl"+ with open(tmp_path, "w") as f:+ for d in data:+ print(json.dumps(d), file=f, end="\n", flush=True)+ return replay_task_instances_path+++ is_github = Falseif data_path.endswith(".jsonl"):- data = [json.loads(x) for x in open(data_path, "r").readlines()]+ replay_task_instances_path = create_task_instances_tmp_file([json.loads(x) for x in open(data_path, "r").readlines()])elif data_path.endswith(".json"):- data = json.load(open(data_path))+ replay_task_instances_path = create_task_instances_tmp_file(json.load(open(data_path)))+ elif is_from_github_url(data_path):+ is_github = True+ replay_task_instances_path = data_pathelse:raise ValueError("--data_path must be a .json or .jsonl")- data = [d for d in data if d["instance_id"] == instance_id]-- with open(replay_task_instances_path, "w") as f:- for d in data:- print(json.dumps(d), file=f, end="\n", flush=True)# Call run.py via subprocesscommand = [@@ -104,12 +117,18 @@ def process_single_traj(traj_path: str, config_file: str, data_path: str, suffix"--model_name", "replay","--replay_path", replay_action_trajs_path,]+ if is_github:+ # Not sure if this only applies to github urls for data_path+ command.extend(["--skip_existing", "False"])if suffix is not None:command.extend(["--suffix", suffix])subprocess.run(command)os.remove(replay_action_trajs_path)- os.remove(replay_task_instances_path)+ try:+ os.remove(replay_task_instances_path)+ except FileNotFoundError:+ passdef main(