From cdec6e2baad70ef368c8fd541e07ff828c943e45 Mon Sep 17 00:00:00 2001 From: stellahsr Date: Tue, 9 Apr 2024 13:43:52 +0800 Subject: [PATCH 1/7] update --- examples/mgx/run_mgx.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/mgx/run_mgx.py b/examples/mgx/run_mgx.py index db396ea03..f4eb31579 100644 --- a/examples/mgx/run_mgx.py +++ b/examples/mgx/run_mgx.py @@ -6,7 +6,8 @@ import asyncio from metagpt.roles.di.mgx import MGX requirement = ( - "design a game using Gym (an open source Python library), including a graphical interface and interactive gameplay" + # "design a game using Gym (an open source Python library), including a graphical interface and interactive gameplay" + 'Create a "2048 game"' ) From 8d78632dd084e8fb4c078f9368e38f09069249fa Mon Sep 17 00:00:00 2001 From: stellahsr Date: Wed, 10 Apr 2024 16:33:38 +0800 Subject: [PATCH 2/7] update local code --- examples/di/rm_image_background.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/di/rm_image_background.py b/examples/di/rm_image_background.py index cb7900a0a..524ecdb33 100644 --- a/examples/di/rm_image_background.py +++ b/examples/di/rm_image_background.py @@ -1,15 +1,16 @@ import asyncio -from metagpt.roles.di.data_interpreter import DataInterpreter +from metagpt.roles.di.mgx import MGX async def main(requirement: str = ""): - di = DataInterpreter() + # di = DataInterpreter() + di = MGX(use_intent=False, tools=[""]) await di.run(requirement) if __name__ == "__main__": - image_path = "/your/path/to/the/image.jpeg" - save_path = "/your/intended/save/path/for/image_rm_bg.png" + image_path = r"F:\deepWisdom\metaGPT\hsr\MetaGPT\examples\data\dog.beebf16d.jpg" + save_path = r"F:\deepWisdom\metaGPT\hsr\MetaGPT\examples\data\/image_rm_bg.png" requirement = f"This is a image, you need to use python toolkit rembg to remove the background of the image and save the result. image path:{image_path}; save path:{save_path}." asyncio.run(main(requirement)) From 780c68e43f813589682d3cf11435b753e228e02f Mon Sep 17 00:00:00 2001 From: stellahsr Date: Wed, 10 Apr 2024 17:00:05 +0800 Subject: [PATCH 3/7] update prompt indention --- metagpt/actions/di/write_plan.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/metagpt/actions/di/write_plan.py b/metagpt/actions/di/write_plan.py index bc4fb4e71..8d6eccf57 100644 --- a/metagpt/actions/di/write_plan.py +++ b/metagpt/actions/di/write_plan.py @@ -16,9 +16,7 @@ from metagpt.schema import Message, Plan, Task from metagpt.strategy.task_type import TaskType from metagpt.utils.common import CodeParser - -class WritePlan(Action): - PROMPT_TEMPLATE: str = """ +PROMPT_TEMPLATE: str = """ # Context: {context} # Available Task Types: @@ -39,11 +37,13 @@ Output a list of jsons following the format: ... ] ``` - """ +""" + +class WritePlan(Action): async def run(self, context: list[Message], max_tasks: int = 5) -> str: task_type_desc = "\n".join([f"- **{tt.type_name}**: {tt.value.desc}" for tt in TaskType]) - prompt = self.PROMPT_TEMPLATE.format( + prompt = PROMPT_TEMPLATE.format( context="\n".join([str(ct) for ct in context]), max_tasks=max_tasks, task_type_desc=task_type_desc ) rsp = await self._aask(prompt) From 4fc24ac98dacc59b35093ca3e2fcffcc1e7c32fc Mon Sep 17 00:00:00 2001 From: stellahsr Date: Wed, 10 Apr 2024 17:14:59 +0800 Subject: [PATCH 4/7] bugfix: return last 500 outputs for !pip execution --- metagpt/actions/di/execute_nb_code.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metagpt/actions/di/execute_nb_code.py b/metagpt/actions/di/execute_nb_code.py index 873c11106..e78c5acf3 100644 --- a/metagpt/actions/di/execute_nb_code.py +++ b/metagpt/actions/di/execute_nb_code.py @@ -27,6 +27,8 @@ from metagpt.actions import Action from metagpt.const import DEFAULT_WORKSPACE_ROOT from metagpt.logs import ToolLogItem, log_tool_output, logger +INSTALL_KEEPLEN = 500 + class ExecuteNbCode(Action): """execute notebook code block, return result to llm, and display it.""" @@ -207,6 +209,7 @@ class ExecuteNbCode(Action): if "!pip" in code: success = False + outputs = outputs[-INSTALL_KEEPLEN:] file_path = DEFAULT_WORKSPACE_ROOT / "code.ipynb" nbformat.write(self.nb, file_path) From f8bea537c07bb090ad05b8faf62adae1e1d3a7a8 Mon Sep 17 00:00:00 2001 From: stellahsr Date: Wed, 10 Apr 2024 17:17:42 +0800 Subject: [PATCH 5/7] rm test path --- examples/di/rm_image_background.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/di/rm_image_background.py b/examples/di/rm_image_background.py index 524ecdb33..cb7900a0a 100644 --- a/examples/di/rm_image_background.py +++ b/examples/di/rm_image_background.py @@ -1,16 +1,15 @@ import asyncio -from metagpt.roles.di.mgx import MGX +from metagpt.roles.di.data_interpreter import DataInterpreter async def main(requirement: str = ""): - # di = DataInterpreter() - di = MGX(use_intent=False, tools=[""]) + di = DataInterpreter() await di.run(requirement) if __name__ == "__main__": - image_path = r"F:\deepWisdom\metaGPT\hsr\MetaGPT\examples\data\dog.beebf16d.jpg" - save_path = r"F:\deepWisdom\metaGPT\hsr\MetaGPT\examples\data\/image_rm_bg.png" + image_path = "/your/path/to/the/image.jpeg" + save_path = "/your/intended/save/path/for/image_rm_bg.png" requirement = f"This is a image, you need to use python toolkit rembg to remove the background of the image and save the result. image path:{image_path}; save path:{save_path}." asyncio.run(main(requirement)) From aa17c250569e1322b53dd34abc8cded88315905b Mon Sep 17 00:00:00 2001 From: stellahsr Date: Wed, 10 Apr 2024 17:29:44 +0800 Subject: [PATCH 6/7] merge --- examples/mgx/run_mgx.py | 1 + metagpt/roles/di/mgx.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/mgx/run_mgx.py b/examples/mgx/run_mgx.py index 1dc59d71a..54d6eb691 100644 --- a/examples/mgx/run_mgx.py +++ b/examples/mgx/run_mgx.py @@ -8,6 +8,7 @@ from metagpt.roles.di.mgx import MGX requirement = ( # "design a game using Gym (an open source Python library), including a graphical interface and interactive gameplay" 'Create a "2048 game"' + # "Create a 2048 Game" ) diff --git a/metagpt/roles/di/mgx.py b/metagpt/roles/di/mgx.py index 1715b9b6c..8e9a0dfae 100644 --- a/metagpt/roles/di/mgx.py +++ b/metagpt/roles/di/mgx.py @@ -4,10 +4,11 @@ import asyncio from typing import Dict -from metagpt.actions.di.detect_intent import DetectIntent +from metagpt.actions.di.detect_intent import DetectIntent, SOPItem from metagpt.logs import logger from metagpt.roles.di.data_interpreter import DataInterpreter from metagpt.schema import Message +from metagpt.tools.tool_recommend import BM25ToolRecommender class MGX(DataInterpreter): @@ -18,6 +19,10 @@ class MGX(DataInterpreter): todo = DetectIntent(context=self.context) request_with_sop, sop_type = await todo.run(user_msg) logger.info(f"{sop_type} {request_with_sop}") + if sop_type == SOPItem.SOFTWARE_DEVELOPMENT.type_name: + self.tool_recommender = BM25ToolRecommender(tools=["software development"]) + else: + self.tool_recommender = BM25ToolRecommender(tools=[""]) return request_with_sop async def _plan_and_act(self) -> Message: From 04a5529cb306f00612efd1bf5b8d2bf70a268e63 Mon Sep 17 00:00:00 2001 From: stellahsr Date: Wed, 10 Apr 2024 17:35:04 +0800 Subject: [PATCH 7/7] sync mgx_ops --- examples/mgx/run_mgx.py | 4 +++- metagpt/tools/libs/software_development.py | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/mgx/run_mgx.py b/examples/mgx/run_mgx.py index 54d6eb691..86aa67ad7 100644 --- a/examples/mgx/run_mgx.py +++ b/examples/mgx/run_mgx.py @@ -7,7 +7,9 @@ from metagpt.roles.di.mgx import MGX requirement = ( # "design a game using Gym (an open source Python library), including a graphical interface and interactive gameplay" - 'Create a "2048 game"' + # "帮我把pip的源设置成:https://pypi.tuna.tsinghua.edu.cn/simple" + # "This is a website url does not require login: https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767 please write a similar web page,developed in vue language, The package.json dependency must be generated" + "I would like to imitate the website available at https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767. Could you please browse through it?" # "Create a 2048 Game" ) diff --git a/metagpt/tools/libs/software_development.py b/metagpt/tools/libs/software_development.py index 9f74c58e1..291fc78d9 100644 --- a/metagpt/tools/libs/software_development.py +++ b/metagpt/tools/libs/software_development.py @@ -86,9 +86,8 @@ async def write_design(prd_path: str | Path) -> Path: Path: The path to the system design files under the project directory. Example: - >>> from metagpt.tools.libs.software_development import write_prd >>> from metagpt.tools.libs.software_development import write_design - >>> prd_path = await write_prd("Create a new feature for the application") + >>> prd_path = '/path/to/project_path/docs/prd' # Returned by `write_prd` >>> system_design_path = await write_desgin(prd_path) >>> print(system_design_path) '/path/to/project_path/docs/system_design/'