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]

Tools: Try enforcing utf-8 everywhere

Kilian Lieretfce933b0777e
diff --git a/tools/edit_anthropic/bin/str_replace_editor b/tools/edit_anthropic/bin/str_replace_editor
index 84fd0a33..4b86ba18 100644
--- a/tools/edit_anthropic/bin/str_replace_editor
+++ b/tools/edit_anthropic/bin/str_replace_editor
@@ -17,6 +17,12 @@ import io
from registry import registry as REGISTRY
+
+# There are some super strange "ascii can't decode x" errors,
+# that can be solved with setting the default encoding for stdout
+# (note that python3.6 doesn't have the reconfigure method)
+sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
+
TRUNCATED_MESSAGE: str = "<response clipped><NOTE>To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with `grep -n` in order to find the line numbers of what you are looking for.</NOTE>"
MAX_RESPONSE_LEN: int = 16000
@@ -494,10 +500,6 @@ class EditTool:
"Please use `str_replace_editor view` with the `view_range` parameter to show selected lines next.</NOTE>"
)
filemap = maybe_truncate(filemap.expandtabs())
- # There are some super strange "ascii can't decode x" errors,
- # that can be solved with setting the default encoding for stdout
- # (note that python3.6 doesn't have the reconfigure method)
- sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
print(filemap)
print(
"<IMPORTANT><NOTE>The above file has been abbreviated. Please use `str_replace editor view` with `view_range` to look at relevant files in detail.</NOTE></IMPORTANT>"