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]

Make patch note more noticeable (#214)

Kilian Lieret30364138ffbe
diff --git a/run.py b/run.py
index 87602bf1..aa36a547 100644
--- a/run.py
+++ b/run.py
@@ -4,6 +4,10 @@ import os
import re
import traceback
from typing import Any, Dict, Optional
+import rich.console
+import rich.markdown
+import rich.panel
+import rich.markdown
import yaml
from dataclasses import dataclass
@@ -257,6 +261,8 @@ def save_predictions(traj_dir: Path, instance_id: str, info):
logger.info(f"Saved predictions to {output_file}")
+
+
def save_patch(traj_dir: Path, instance_id: str, info) -> Optional[Path]:
"""Create patch files that can be applied with `git am`.
@@ -271,10 +277,35 @@ def save_patch(traj_dir: Path, instance_id: str, info) -> Optional[Path]:
return
model_patch = info["submission"]
patch_output_file.write_text(model_patch)
- logger.info(f"Saved patch to {patch_output_file}")
+ _print_patch_message(patch_output_file)
return patch_output_file
+def _print_patch_message(patch_output_file: Path):
+ console = rich.console.Console()
+ msg = [
+ "SWE-agent has produced a patch that it believes will solve the issue you submitted!",
+ "Use the code snippet below to inspect or apply it!"
+ ]
+ panel = rich.panel.Panel.fit(
+ "\n".join(msg),
+ title="🎉 Submission successful 🎉",
+ )
+ console.print(panel)
+ content = [
+ "```bash",
+ f"# The patch has been saved to your local filesystem at:",
+ f"PATCH_FILE_PATH='{patch_output_file.resolve()}'",
+ "# Inspect it:",
+ "cat \"${PATCH_FILE_PATH}\"",
+ "# Apply it to a local repository:",
+ f"cd <your local repo root>",
+ "git apply \"${PATCH_FILE_PATH}\"",
+ "```",
+ ]
+ console.print(rich.markdown.Markdown("\n".join(content)))
+
+
def get_args(args=None) -> ScriptArguments:
"""Parse command line arguments and return a ScriptArguments object.