From fce3d55f7fa34f9a3a0da23ffa414dc1bcc7adda Mon Sep 17 00:00:00 2001 From: femto Date: Mon, 11 Sep 2023 16:59:23 +0800 Subject: [PATCH] change prompt a bit --- metagpt/actions/design_api.py | 2 +- metagpt/actions/project_management.py | 2 +- metagpt/actions/write_prd.py | 2 +- metagpt/actions/write_test.py | 10 +++++++++- metagpt/roles/qa_engineer.py | 13 ++++++++++--- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/metagpt/actions/design_api.py b/metagpt/actions/design_api.py index a2192c4dc..cde366533 100644 --- a/metagpt/actions/design_api.py +++ b/metagpt/actions/design_api.py @@ -24,7 +24,7 @@ PROMPT_TEMPLATE = """ {format_example} ----- Role: You are an architect; the goal is to design a SOTA PEP8-compliant python system; make the best use of good open source tools -Requirement: Fill in the following missing information based on the context, note that all sections are response with code form separately +Requirement: Fill in the following missing information based on the context, each section name is a key in json Max Output: 8192 chars or 2048 tokens. Try to use them up. ## Implementation approach: Provide as Plain text. Analyze the difficult points of the requirements, select the appropriate open-source framework. diff --git a/metagpt/actions/project_management.py b/metagpt/actions/project_management.py index 40b3204ab..5ae3a728c 100644 --- a/metagpt/actions/project_management.py +++ b/metagpt/actions/project_management.py @@ -20,7 +20,7 @@ PROMPT_TEMPLATE = """ {format_example} ----- Role: You are a project manager; the goal is to break down tasks according to PRD/technical design, give a task list, and analyze task dependencies to start with the prerequisite modules -Requirements: Based on the context, fill in the following missing information, note that all sections are returned in Python code triple quote form seperatedly. Here the granularity of the task is a file, if there are any missing files, you can supplement them +Requirements: Based on the context, fill in the following missing information, each section name is a key in json. Here the granularity of the task is a file, if there are any missing files, you can supplement them Attention: Use '##' to split sections, not '#', and '## ' SHOULD WRITE BEFORE the code and triple quote. ## Required Python third-party packages: Provided in requirements.txt format diff --git a/metagpt/actions/write_prd.py b/metagpt/actions/write_prd.py index 99f057da4..99032c2de 100644 --- a/metagpt/actions/write_prd.py +++ b/metagpt/actions/write_prd.py @@ -42,7 +42,7 @@ quadrantChart {format_example} ----- Role: You are a professional product manager; the goal is to design a concise, usable, efficient product -Requirements: According to the context, fill in the following missing information, note that each sections are returned in Python code triple quote form seperatedly. If the requirements are unclear, ensure minimum viability and avoid excessive design +Requirements: According to the context, fill in the following missing information, each section name is a key in json ,If the requirements are unclear, ensure minimum viability and avoid excessive design ## Original Requirements: Provide as Plain text, place the polished complete original requirements here diff --git a/metagpt/actions/write_test.py b/metagpt/actions/write_test.py index ddf65c373..0429cb973 100644 --- a/metagpt/actions/write_test.py +++ b/metagpt/actions/write_test.py @@ -35,7 +35,15 @@ class WriteTest(Action): async def write_code(self, prompt): code_rsp = await self._aask(prompt) - code = CodeParser.parse_code(block="", text=code_rsp) + + try: + code = CodeParser.parse_code(block="", text=code_rsp) + except Exception as e: + # Handle the exception if needed + print(f"An exception occurred: {str(e)}") + + # Return code_rsp in case of an exception, assuming llm just returns code as it is and doesn't wrap it inside ``` + code = code_rsp return code async def run(self, code_to_test, test_file_name, source_file_path, workspace): diff --git a/metagpt/roles/qa_engineer.py b/metagpt/roles/qa_engineer.py index 543912f3c..a763c2ce8 100644 --- a/metagpt/roles/qa_engineer.py +++ b/metagpt/roles/qa_engineer.py @@ -8,7 +8,14 @@ import os from pathlib import Path -from metagpt.actions import DebugError, RunCode, WriteCode, WriteDesign, WriteTest +from metagpt.actions import ( + DebugError, + RunCode, + WriteCode, + WriteCodeReview, + WriteDesign, + WriteTest, +) from metagpt.const import WORKSPACE_ROOT from metagpt.logs import logger from metagpt.roles import Role @@ -30,7 +37,7 @@ class QaEngineer(Role): self._init_actions( [WriteTest] ) # FIXME: a bit hack here, only init one action to circumvent _think() logic, will overwrite _think() in future updates - self._watch([WriteCode, WriteTest, RunCode, DebugError]) + self._watch([WriteCode, WriteCodeReview, WriteTest, RunCode, DebugError]) self.test_round = 0 self.test_round_allowed = test_round_allowed @@ -159,7 +166,7 @@ class QaEngineer(Role): for msg in self._rc.news: # Decide what to do based on observed msg type, currently defined by human, # might potentially be moved to _think, that is, let the agent decides for itself - if msg.cause_by == WriteCode: + if msg.cause_by in [WriteCode, WriteCodeReview]: # engineer wrote a code, time to write a test for it await self._write_test(msg) elif msg.cause_by in [WriteTest, DebugError]: