mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
update mode from "guide" to "incremental" in get_codes function of write_code.py
This commit is contained in:
parent
81b59bfe0d
commit
69ad2f4147
4 changed files with 11 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue