From cc40534e3779c6450c7da3b857452c12203134af Mon Sep 17 00:00:00 2001 From: garylin2099 Date: Thu, 15 Aug 2024 17:02:08 +0800 Subject: [PATCH 1/2] minor update, read csv --- metagpt/prompts/di/data_analyst.py | 4 ++-- metagpt/tools/libs/editor.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/metagpt/prompts/di/data_analyst.py b/metagpt/prompts/di/data_analyst.py index 9d7f3ec50..f534977aa 100644 --- a/metagpt/prompts/di/data_analyst.py +++ b/metagpt/prompts/di/data_analyst.py @@ -8,8 +8,8 @@ EXTRA_INSTRUCTION = """ - For information searching requirement, you should use the Browser tool instead of web scraping. - When no link is provided, you should use the Browser tool to search for the information. 7. When you are making plan. It is highly recommend to plan and append all the tasks in first response once time, except for 7.1. -7.1. When the requirement is given with a file, read the file first through either Editor.read (write code instead for excel) WITHOUT a plan. After reading the file content, use RoleZero.reply_to_human if the requirement can be answered straightaway, otherwise, make a plan if further calculation is needed. -8. Don't finish_current_task multiple times for the same task. +7.1. When the requirement is given with a file, read the file first through either Editor.read (write code instead for csv or excel) WITHOUT a plan. After reading the file content, use RoleZero.reply_to_human if the requirement can be answered straightaway, otherwise, make a plan if further calculation is needed. +8. Don't finish_current_task multiple times for the same task. 9. Finish current task timely, such as when the code is written and executed successfully. 10. When using the command 'end', add the command 'finish_current_task' before it. """ diff --git a/metagpt/tools/libs/editor.py b/metagpt/tools/libs/editor.py index d8023715b..542993516 100644 --- a/metagpt/tools/libs/editor.py +++ b/metagpt/tools/libs/editor.py @@ -26,7 +26,7 @@ class FileBlock(BaseModel): class Editor(BaseModel): """ A tool for reading, understanding, writing, and editing files. - Support local file including text-based files (txt, md, json, py, html, js, css, etc.), pdf, docx, excluding images, excel, or online links + Support local file including text-based files (txt, md, json, py, html, js, css, etc.), pdf, docx, excluding images, csv, excel, or online links """ model_config = ConfigDict(arbitrary_types_allowed=True) From eda70be277e277503c49c78a2ddbe5b6989623ce Mon Sep 17 00:00:00 2001 From: garylin2099 Date: Thu, 15 Aug 2024 17:04:27 +0800 Subject: [PATCH 2/2] add role info for regular think sys prompt --- metagpt/prompts/di/role_zero.py | 4 +++- metagpt/roles/di/role_zero.py | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index cc78d809c..d12363f4f 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -22,6 +22,8 @@ Note: ########################### SYSTEM_PROMPT = """ +# Basic Info +{role_info} # Data Structure class Task(BaseModel): @@ -206,4 +208,4 @@ Response Category: AMBIGUOUS. QUICK_RESPONSE_SYSTEM_PROMPT = """ {role_info} However, you MUST respond to the user message by yourself directly, DON'T ask your team members. -""" \ No newline at end of file +""" diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 3ceee8b43..91b39f5ba 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -21,10 +21,10 @@ from metagpt.prompts.di.role_zero import ( ASK_HUMAN_COMMAND, CMD_PROMPT, JSON_REPAIR_PROMPT, - QUICK_THINK_PROMPT, - QUICK_THINK_EXAMPLES, - QUICK_THINK_SYSTEM_PROMPT, QUICK_RESPONSE_SYSTEM_PROMPT, + QUICK_THINK_EXAMPLES, + QUICK_THINK_PROMPT, + QUICK_THINK_SYSTEM_PROMPT, REGENERATE_PROMPT, ROLE_INSTRUCTION, SYSTEM_PROMPT, @@ -166,7 +166,11 @@ class RoleZero(Role): ### Role Instruction ### instruction = self.instruction.strip() system_prompt = self.system_prompt.format( - task_type_desc=self.task_type_desc, available_commands=tool_info, example=example, instruction=instruction + role_info=self._get_prefix(), + task_type_desc=self.task_type_desc, + available_commands=tool_info, + example=example, + instruction=instruction, ) ### Make Decision Dynamically ### @@ -269,7 +273,7 @@ class RoleZero(Role): rsp = await self._act() actions_taken += 1 return rsp # return output from the last action - + def format_quick_system_prompt(self) -> str: """Format the system prompt for quick thinking.""" return QUICK_THINK_SYSTEM_PROMPT.format(examples=QUICK_THINK_EXAMPLES, role_info=self._get_prefix()) @@ -289,7 +293,10 @@ class RoleZero(Role): if "QUICK" in intent_result or "AMBIGUOUS" in intent_result: # llm call with the original context async with ThoughtReporter(enable_llm_stream=True) as reporter: await reporter.async_report({"type": "quick"}) - answer = await self.llm.aask(self.llm.format_msg(memory), system_msgs=[QUICK_RESPONSE_SYSTEM_PROMPT.format(role_info=self._get_prefix())]) + answer = await self.llm.aask( + self.llm.format_msg(memory), + system_msgs=[QUICK_RESPONSE_SYSTEM_PROMPT.format(role_info=self._get_prefix())], + ) elif "SEARCH" in intent_result: query = "\n".join(str(msg) for msg in memory) answer = await SearchEnhancedQA().run(query)