From 6365995f71bf43c4989c7dbba792a73301f1582c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Mon, 9 Sep 2024 20:48:42 +0800 Subject: [PATCH] remove requirements_constraints --- metagpt/prompts/di/role_zero.py | 19 ++++++++++++------- metagpt/prompts/di/team_leader.py | 7 ++++--- metagpt/roles/di/role_zero.py | 12 ++++++------ metagpt/strategy/experience_retriever.py | 6 +++--- src/index.html | 21 +++++++++++++++++++++ 5 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 src/index.html diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index bc14cc555..729a22090 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -44,11 +44,9 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet # Example {example} -# Role Instruction +# Instruction {instruction} -# Common Instruction -1. Choose a language the user can understand for responding. Usually, use the same as the user's message. """ CMD_EXPERIENCE_MASK = f""" @@ -67,8 +65,8 @@ CMD_PROMPT = ( # Current Task {current_task} -# Restrictions -{requirements_constraints} +# Respond Language +you must respond in {respond_language}. Pay close attention to the Example provided, you can reuse the example for your current situation if it fits. You may use any of the available commands to create a plan or update the plan. You may output mutiple commands, they will be executed sequentially. @@ -90,7 +88,6 @@ Output should adhere to the following format. ] ``` Notice: your output JSON data section must start with **```json [** -Firstly, the language of the response is... """ ) THOUGHT_GUIDANCE = """ @@ -239,7 +236,7 @@ reply : The herb names have been successfully extracted. A total of 8 herb names Carefully review the history and respond to the user in the expected language to meet their requirements. If you have any deliverables that are helpful in explaining the results (such as files, metrics, quantitative results, etc.), provide brief descriptions of them. Your reply must be concise. -{lanaguge_restruction} +You must respond in {respond_language} Directly output your reply content. Do not add any output format. """ SUMMARY_PROMPT = """ @@ -247,3 +244,11 @@ Summarize what you have accomplished lately. Be concise. If you produce any deliverables, include their short descriptions and file paths. If there are any metrics or quantitative results, include them, too. If the deliverable is code, only output the file path. """ + +RESPOND_LANGUAGE_DETECT = """ +The requirement is: +{requirement} + +Which Natural Language must you respond in? +Output only the language type. +""" diff --git a/metagpt/prompts/di/team_leader.py b/metagpt/prompts/di/team_leader.py index 01c8de20f..f2dcd722b 100644 --- a/metagpt/prompts/di/team_leader.py +++ b/metagpt/prompts/di/team_leader.py @@ -32,9 +32,10 @@ Note: 9. Do not use the 'end' command when the current task remains unfinished; instead, use the 'finish_current_task' command to indicate completion before switching to the next task. 10. Do not use escape characters in json data, particularly within file paths. 11. Analyze the capabilities of team members and assign tasks to them based on user Requirements. If the requirements ask to ignore certain tasks, follow the requirements. -12.Default technology stack is HTML (.html), CSS (.css), and JavaScript (.js). When developing software, include this stack and add any specific programming languages to the instructions. -13. If the the user message is a question. use 'reply to human' to respond to the question, and then end. -14. Instructions and reply must be in the same language. +12. If the the user message is a question. use 'reply to human' to respond to the question, and then end. +13. Instructions and reply must be in the same language. +14. Default technology stack is HTML (.html), CSS (.css), and JavaScript (.js). Web app is the default option when developing software. +15. You are the only one who decides the programming language for the software, so the instruction must contain the programming language. """ TL_THOUGHT_GUIDANCE = ( THOUGHT_GUIDANCE diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 58925ce99..6e5618faa 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -27,6 +27,7 @@ from metagpt.prompts.di.role_zero import ( QUICK_THINK_SYSTEM_PROMPT, REGENERATE_PROMPT, REPORT_TO_HUMAN_PROMPT, + RESPOND_LANGUAGE_DETECT, ROLE_INSTRUCTION, SUMMARY_PROMPT, SYSTEM_PROMPT, @@ -91,7 +92,7 @@ class RoleZero(Role): commands: list[dict] = [] # commands to be executed memory_k: int = 200 # number of memories (messages) to use as historical context use_fixed_sop: bool = False - requirements_constraints: str = "" # the constraints in user requirements + respond_language: str = "" # the constraints of respond language use_summary: bool = True # whether to summarize at the end @model_validator(mode="after") @@ -178,7 +179,8 @@ class RoleZero(Role): if not self.planner.plan.goal: self.planner.plan.goal = self.get_memories()[-1].content - + repond_language_detect = RESPOND_LANGUAGE_DETECT.format(requirement=self.planner.plan.goal) + self.respond_language = await self.llm.aask(repond_language_detect) ### 1. Experience ### example = self._retrieve_experience() @@ -204,7 +206,7 @@ class RoleZero(Role): current_state=self.cmd_prompt_current_state, plan_status=plan_status, current_task=current_task, - requirements_constraints=self.requirements_constraints, + respond_language=self.respond_language, ) ### Recent Observation ### @@ -547,9 +549,7 @@ class RoleZero(Role): # Ensure reply to the human before the "end" command is executed. Hard code k=5 for checking. if not any(["reply_to_human" in memory.content for memory in self.get_memories(k=5)]): logger.info("manually reply to human") - pattern = r"\[Language Restrictions\](.*?)\n" - match = re.search(pattern, self.requirements_constraints, re.DOTALL) - reply_to_human_prompt = REPORT_TO_HUMAN_PROMPT.format(lanaguge_restruction=match.group(0) if match else "") + reply_to_human_prompt = REPORT_TO_HUMAN_PROMPT.format(respond_language=self.respond_language) async with ThoughtReporter(enable_llm_stream=True) as reporter: await reporter.async_report({"type": "quick"}) reply_content = await self.llm.aask(self.llm.format_msg(memory + [UserMessage(reply_to_human_prompt)])) diff --git a/metagpt/strategy/experience_retriever.py b/metagpt/strategy/experience_retriever.py index 9f4ae944e..268a3e7a0 100644 --- a/metagpt/strategy/experience_retriever.py +++ b/metagpt/strategy/experience_retriever.py @@ -479,7 +479,7 @@ Explanation: The requirement is about software development. Assign each tasks to "args": { "task_id": "1", "dependent_task_ids": [], - "instruction": "Create a product requirement document (PRD) outlining the features, user interface. Using ... as the programming language.", + "instruction": "Using HTML, CSS, JavaScrip as the programming language. And create a product requirement document (PRD) outlining the features, user interface. ", "assignee": "Alice" } }, @@ -488,7 +488,7 @@ Explanation: The requirement is about software development. Assign each tasks to "args": { "task_id": "2", "dependent_task_ids": ["1"], - "instruction": "Design the software architecture for the CLI snake game, including the choice of programming language, libraries, and data flow. Using ... as the programming language.", + "instruction": "Using HTML, CSS, JavaScrip as the programming language. Design the software architecture for the CLI snake game, including the data flow.", "assignee": "Bob" } }, @@ -513,7 +513,7 @@ Explanation: The requirement is about software development. Assign each tasks to { "command_name": "TeamLeader.publish_message", "args": { - "content": "Create a cli snake game. Using ... as the programming language.", + "content": "Using HTML, CSS, JavaScrip as the programming language. Create a cli snake game.", "send_to": "Alice" } }, diff --git a/src/index.html b/src/index.html new file mode 100644 index 000000000..1bf94c961 --- /dev/null +++ b/src/index.html @@ -0,0 +1,21 @@ + + + + + + Flappy Bird + + + +
+
+
+
+
+
+
+
Score: 0
+
+ + + \ No newline at end of file