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]

Move traj-to-demo into main run package

Kilian Liereta9925aa49817
diff --git a/make_demos/README.md b/make_demos/README.md
deleted file mode 100644
index 7f63b9e4..00000000
--- a/make_demos/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-🔗 For more information on the trajectory inspector, visit [our documentation website][docs].
-
-You can also find the corresponding markdown files in the [`docs/` folder][source].
-
-[docs]: https://princeton-nlp.github.io/SWE-agent/config/demonstrations/
-[source]: https://github.com/princeton-nlp/SWE-agent/tree/main/docs
diff --git a/sweagent/run/run.py b/sweagent/run/run.py
index 65f38cf9..d862ff31 100644
--- a/sweagent/run/run.py
+++ b/sweagent/run/run.py
@@ -5,14 +5,10 @@ Specify one of the subcommands.
import argparse
import sys
-from sweagent.run.run_batch import run_from_cli as run_batch_main
-from sweagent.run.run_replay import run_from_cli as run_replay_main
-from sweagent.run.run_single import run_from_cli as run_single_main
-
def get_cli():
parser = argparse.ArgumentParser(add_help=False)
- parser.add_argument("command", choices=["run", "run-batch", "run-replay"], nargs="?")
+ parser.add_argument("command", choices=["run", "run-batch", "run-replay", "traj-to-demo"], nargs="?")
parser.add_argument("-h", "--help", action="store_true", help="Show this help message and exit")
return parser
@@ -36,11 +32,21 @@ def main(args: list[str] | None = None):
cli.print_help()
sys.exit(2)
if command == "run":
+ from sweagent.run.run_single import run_from_cli as run_single_main
+
run_single_main(remaining_args)
elif command == "run-batch":
+ from sweagent.run.run_batch import run_from_cli as run_batch_main
+
run_batch_main(remaining_args)
elif command == "run-replay":
+ from sweagent.run.run_replay import run_from_cli as run_replay_main
+
run_replay_main(remaining_args)
+ elif command == "traj-to-demo":
+ from sweagent.run.run_traj_to_demo import run_from_cli as convert_traj_to_demo_main
+
+ convert_traj_to_demo_main(remaining_args)
else:
msg = f"Unknown command: {command}"
raise ValueError(msg)
diff --git a/make_demos/convert_traj_to_demo.py b/sweagent/run/run_traj_to_demo.py
similarity index 92%
rename from make_demos/convert_traj_to_demo.py
rename to sweagent/run/run_traj_to_demo.py
index 53ed3373..407d28b3 100644
--- a/make_demos/convert_traj_to_demo.py
+++ b/sweagent/run/run_traj_to_demo.py
@@ -57,7 +57,7 @@ def save_demo(data, file, traj_path):
f.write(f"{header}\n{content}")
-def convert_traj_to_action_demo(traj_path: str, output_file: str = None, include_user: bool = False):
+def convert_traj_to_action_demo(traj_path: str, output_file: str | Path, include_user: bool = False):
with open(traj_path) as file:
traj = json.load(file)
@@ -71,7 +71,7 @@ def convert_traj_to_action_demo(traj_path: str, output_file: str = None, include
print(f"Saved demo to {output_file}")
-def main(traj_path: str, output_dir: str = None, suffix: str = "", overwrite: bool = False, include_user: bool = False):
+def main(traj_path: str, output_dir: str, suffix: str = "", overwrite: bool = False, include_user: bool = False):
filename = (
"/".join([Path(traj_path).parent.name + suffix, Path(traj_path).name.rsplit(".traj", 1)[0]]) + ".demo.yaml"
)
@@ -93,7 +93,7 @@ def string2bool(s):
raise ValueError(msg)
-if __name__ == "__main__":
+def run_from_cli(args: list[str] | None = None):
parser = ArgumentParser()
parser.add_argument("traj_path", type=str, help="Path to trajectory file")
parser.add_argument("--output_dir", type=str, help="Output directory for action demos", default="./demos")
@@ -106,5 +106,9 @@ if __name__ == "__main__":
default=False,
nargs="?",
)
- args = parser.parse_args()
- main(**vars(args))
+ parsed_args = parser.parse_args(args)
+ main(**vars(parsed_args))
+
+
+if __name__ == "__main__":
+ run_from_cli()