From d57d4f3c01bb8550424c17490bec805e381beedf Mon Sep 17 00:00:00 2001 From: garylin2099 Date: Thu, 13 Jun 2024 20:51:03 +0800 Subject: [PATCH] fix one line content (\\n issue) for editor --- metagpt/tools/libs/editor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/metagpt/tools/libs/editor.py b/metagpt/tools/libs/editor.py index 23df02edd..eba1a1eac 100644 --- a/metagpt/tools/libs/editor.py +++ b/metagpt/tools/libs/editor.py @@ -1,4 +1,5 @@ import os +import re import shutil import subprocess @@ -26,6 +27,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 + content = content.replace("\\n", "\n") directory = os.path.dirname(path) if directory and not os.path.exists(directory): os.makedirs(directory)