From 69ad2f414757a0df131d102dd9effbe99016fae5 Mon Sep 17 00:00:00 2001 From: mannaandpoem <1580466765@qq.com> Date: Fri, 19 Jan 2024 14:53:19 +0800 Subject: [PATCH] update mode from "guide" to "incremental" in get_codes function of write_code.py --- metagpt/actions/write_code.py | 12 +++++++----- metagpt/actions/write_code_plan_and_change_an.py | 2 +- metagpt/actions/write_code_review.py | 2 +- metagpt/roles/engineer.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/metagpt/actions/write_code.py b/metagpt/actions/write_code.py index 662524518..489c4ccb6 100644 --- a/metagpt/actions/write_code.py +++ b/metagpt/actions/write_code.py @@ -125,7 +125,9 @@ class WriteCode(Action): if bug_feedback: code_context = coding_context.code_doc.content elif code_plan_and_change: - code_context = await self.get_codes(coding_context.task_doc, exclude=self.context.filename, mode="guide") + code_context = await self.get_codes( + coding_context.task_doc, exclude=self.context.filename, mode="incremental" + ) else: code_context = await self.get_codes(coding_context.task_doc, exclude=self.context.filename) @@ -161,14 +163,14 @@ class WriteCode(Action): return coding_context @staticmethod - async def get_codes(task_doc: Document, exclude: str, mode: Literal["normal", "guide"] = "normal") -> str: + async def get_codes(task_doc: Document, exclude: str, mode: Literal["normal", "incremental"] = "normal") -> str: """ Get code snippets based on different modes. Attributes: task_doc (Document): Document object of the task file. exclude (str): Specifies the filename to be excluded from the code snippets. - mode (str): Specifies the mode, either "normal" or "guide" (default is "normal"). + mode (str): Specifies the mode, either "normal" or "incremental" (default is "normal"). Returns: str: Code snippets. @@ -177,7 +179,7 @@ class WriteCode(Action): If mode is set to "normal", it returns code snippets for the regular coding phase, i.e., all the code generated before writing the current file. - If mode is set to "guide", it returns code snippets for generating the code plan and change, + If mode is set to "incremental", it returns code snippets for generating the code plan and change, building upon the existing code in the "normal" mode and adding code for the current file's older versions. """ if not task_doc: @@ -189,7 +191,7 @@ class WriteCode(Action): codes = [] src_file_repo = CONFIG.git_repo.new_file_repository(relative_path=CONFIG.src_workspace) - if mode == "guide": + if mode == "incremental": src_files = src_file_repo.all_files old_file_repo = CONFIG.git_repo.new_file_repository(relative_path=CONFIG.old_workspace) old_files = old_file_repo.all_files diff --git a/metagpt/actions/write_code_plan_and_change_an.py b/metagpt/actions/write_code_plan_and_change_an.py index 151b2dc25..db0b73554 100644 --- a/metagpt/actions/write_code_plan_and_change_an.py +++ b/metagpt/actions/write_code_plan_and_change_an.py @@ -194,7 +194,7 @@ class WriteCodePlanAndChange(Action): prd = "\n".join([doc.content for doc in self.context.prd_docs]) design = "\n".join([doc.content for doc in self.context.design_docs]) tasks = "\n".join([doc.content for doc in self.context.task_docs]) - code_text = self.get_old_codes() + code_text = await self.get_old_codes() context = CODE_PLAN_AND_CHANGE_CONTEXT.format( requirement=requirement, prd=prd, design=design, tasks=tasks, code=code_text ) diff --git a/metagpt/actions/write_code_review.py b/metagpt/actions/write_code_review.py index 6dbcb03fa..80f9dd36d 100644 --- a/metagpt/actions/write_code_review.py +++ b/metagpt/actions/write_code_review.py @@ -149,7 +149,7 @@ class WriteCodeReview(Action): filename=CODE_PLAN_AND_CHANGE_FILENAME, relative_path=CODE_PLAN_AND_CHANGE_FILE_REPO ) code_plan_and_change = code_plan_and_change_doc.content if code_plan_and_change_doc else "" - mode = "guide" if code_plan_and_change else "normal" + mode = "incremental" if code_plan_and_change else "normal" for i in range(k): format_example = FORMAT_EXAMPLE.format(filename=self.context.code_doc.filename) diff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.py index 4d265f4df..44db2e8a0 100644 --- a/metagpt/roles/engineer.py +++ b/metagpt/roles/engineer.py @@ -106,7 +106,7 @@ class Engineer(Role): m = json.loads(task_msg.content) return m.get(TASK_LIST.key) or m.get(REFINED_TASK_LIST.key) - async def _act_sp_with_cr(self, review=False, mode: Literal["normal", "guide"] = "normal") -> Set[str]: + async def _act_sp_with_cr(self, review=False, mode: Literal["normal", "incremental"] = "normal") -> Set[str]: changed_files = set() src_file_repo = CONFIG.git_repo.new_file_repository(CONFIG.src_workspace) for todo in self.code_todos: @@ -126,7 +126,7 @@ class Engineer(Role): dependencies = {coding_context.design_doc.root_relative_path, coding_context.task_doc.root_relative_path} # TODO: Add code plan and change file to context when _think - if mode == "guide": + if mode == "incremental": dependencies.add(os.path.join(CODE_PLAN_AND_CHANGE_FILE_REPO, CODE_PLAN_AND_CHANGE_FILENAME)) await src_file_repo.save( coding_context.filename,