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]

Fix: Make sure output folder exists

Kilian Lieret3b3f0cd063a2
diff --git a/sweagent/run/common.py b/sweagent/run/common.py
index d7cce36f..fbbbc9a6 100644
--- a/sweagent/run/common.py
+++ b/sweagent/run/common.py
@@ -361,6 +361,7 @@ class BasicCLI:
def save_predictions(traj_dir: Path, instance_id: str, result: AgentRunResult):
"""Save predictions in a file readable by SWE-bench"""
output_file = traj_dir / instance_id / (instance_id + ".pred")
+ output_file.parent.mkdir(parents=True, exist_ok=True)
datum = {
"model_name_or_path": traj_dir.name,
"instance_id": instance_id,
diff --git a/sweagent/run/hooks/apply_patch.py b/sweagent/run/hooks/apply_patch.py
index 6d9e97d8..f3a982d8 100644
--- a/sweagent/run/hooks/apply_patch.py
+++ b/sweagent/run/hooks/apply_patch.py
@@ -75,9 +75,9 @@ class SaveApplyPatchHook(RunHook):
Returns:
The path to the patch file, if it was saved. Otherwise, returns None.
"""
- patch_output_dir = self._output_dir
+ patch_output_dir = self._output_dir / instance_id
patch_output_dir.mkdir(exist_ok=True, parents=True)
- patch_output_file = patch_output_dir / instance_id / f"{instance_id}.patch"
+ patch_output_file = patch_output_dir / f"{instance_id}.patch"
if info.get("submission") is None:
self.logger.info("No patch to save.")
return None
diff --git a/sweagent/utils/log.py b/sweagent/utils/log.py
index 107d68f2..8544d3e9 100644
--- a/sweagent/utils/log.py
+++ b/sweagent/utils/log.py
@@ -5,7 +5,7 @@ import os
import threading
import uuid
from collections.abc import Callable
-from pathlib import PurePath
+from pathlib import Path, PurePath
from rich.logging import RichHandler
from rich.text import Text
@@ -107,6 +107,7 @@ def add_file_handler(
Returns:
The id of the handler. This can be used to remove the handler later.
"""
+ Path(path).parent.mkdir(parents=True, exist_ok=True)
handler = logging.FileHandler(path)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
handler.setFormatter(formatter)