🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
Handle potential incorrect newline representations in FileWriter.write()
shenchucheng9d06f9f4f8a0
diff --git a/metagpt/tools/libs/editor.py b/metagpt/tools/libs/editor.pyindex d145fdabe..c9f02c4f1 100644--- a/metagpt/tools/libs/editor.py+++ b/metagpt/tools/libs/editor.py@@ -1,5 +1,4 @@import os-import reimport shutilimport subprocess@@ -27,8 +26,9 @@ class Editor:def write(self, path: str, content: str):"""Write the whole content to a file. When used, make sure content arg contains the full content of the file."""- if len(re.findall(r"\\n", content)) >= 5:- # A very raw rule to correct the content: Many \\n suggests all new line characters are mistaken as \\n whereas the correct one should be \n+ if "\n" not in content and "\\n" in content:+ # A very raw rule to correct the content: If 'content' lacks actual newlines ('\n') but includes '\\n', consider+ # replacing them with '\n' to potentially correct mistaken representations of newline characters.content = content.replace("\\n", "\n")directory = os.path.dirname(path)if directory and not os.path.exists(directory):