🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
user commom.awrite in Editr.create_file
黄伟韬b7ef5d67181b
diff --git a/metagpt/tools/libs/editor.py b/metagpt/tools/libs/editor.pyindex c49d33a6e..b297c9989 100644--- a/metagpt/tools/libs/editor.py+++ b/metagpt/tools/libs/editor.py@@ -17,6 +17,7 @@ from metagpt.const import DEFAULT_WORKSPACE_ROOTfrom metagpt.tools.libs.index_repo import DEFAULT_MIN_TOKEN_COUNT, IndexRepofrom metagpt.tools.libs.linter import Linterfrom metagpt.tools.tool_registry import register_tool+from metagpt.utils.common import awritefrom metagpt.utils.file import Filefrom metagpt.utils.report import EditorReporter@@ -348,7 +349,7 @@ class Editor(BaseModel):output += self._print_window(self.current_file, self.current_line, self.window)return output- def create_file(self, filename: str) -> str:+ async def create_file(self, filename: str) -> str:"""Creates and opens a new file with the given name.Args:@@ -358,10 +359,7 @@ class Editor(BaseModel):if filename.exists():raise FileExistsError(f"File '{filename}' already exists.")- if not filename.parent.exists():- os.makedirs(filename.parent, exist_ok=True)- with filename.open("w") as file:- file.write("\n")+ await awrite(filename, "\n")self.open_file(filename)return f"[File {filename} created.]"diff --git a/tests/metagpt/tools/libs/test_editor.py b/tests/metagpt/tools/libs/test_editor.pyindex 81964440a..8d6e923af 100644--- a/tests/metagpt/tools/libs/test_editor.py+++ b/tests/metagpt/tools/libs/test_editor.py@@ -270,9 +270,10 @@ def test_create_file_unexist_path():editor.create_file("/unexist/path/a.txt")-def test_create_file(temp_file_path):+async def test_create_file(temp_file_path):editor = Editor()- result = editor.create_file(str(temp_file_path))+ result = await editor.create_file(str(temp_file_path))expected = f"[File {temp_file_path} created.]"assert result.split("\n") == expected.split("\n")