From eef0375c6c8ef4ddca9de542c33f428b1cbf8f26 Mon Sep 17 00:00:00 2001 From: stellahsr Date: Tue, 9 Apr 2024 17:37:49 +0800 Subject: [PATCH] update tools according to intention update TaskTypeDef for software development --- examples/mgx/run_mgx.py | 6 +++--- metagpt/actions/di/detect_intent.py | 6 ++++-- metagpt/actions/di/write_plan.py | 18 +++++++++--------- metagpt/roles/di/mgx.py | 7 ++++++- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/mgx/run_mgx.py b/examples/mgx/run_mgx.py index edfaff3d7..86aa67ad7 100644 --- a/examples/mgx/run_mgx.py +++ b/examples/mgx/run_mgx.py @@ -9,13 +9,13 @@ requirement = ( # "design a game using Gym (an open source Python library), including a graphical interface and interactive gameplay" # "帮我把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" + "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" ) async def main(requirement: str = ""): - mgx = MGX(use_intent=True, tools=["software development"]) + mgx = MGX(use_intent=True, tools=[""]) await mgx.run(requirement) diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.py index 5d25e9fbe..d7187c4f3 100644 --- a/metagpt/actions/di/detect_intent.py +++ b/metagpt/actions/di/detect_intent.py @@ -98,10 +98,12 @@ To meet user requirements, the following standard operating procedure(SOP) must {sop} -### SOP Type -{sop_type} + """ +### SOP Type +# {sop_type} + class DetectIntent(Action): async def run(self, with_message: Message, **kwargs) -> Tuple[str, str]: diff --git a/metagpt/actions/di/write_plan.py b/metagpt/actions/di/write_plan.py index 83709bc1a..201280d9b 100644 --- a/metagpt/actions/di/write_plan.py +++ b/metagpt/actions/di/write_plan.py @@ -29,15 +29,15 @@ If you are modifying an existing plan, carefully follow the instruction, don't m If you encounter errors on the current task, revise and output the current single task only. Output a list of jsons following the format: ```json -[ - {{ - "task_id": str = "unique identifier for a task in plan, can be an ordinal", - "dependent_task_ids": list[str] = "ids of tasks prerequisite to this task", - "instruction": "what you should do in this task, one short phrase or sentence. If the SOP description is provided in the `Knowledge` section, the reference to the SOP description should be included intact in the instruction.", - "task_type": "type of this task, should be one of Available Task Types. You can refer to the hints in the `SOP Type` section to make a selection if `SOP Type` section is provided.", - }}, - ... -] + [ + {{ + "task_id": str = "unique identifier for a task in plan, can be an ordinal", + "dependent_task_ids": list[str] = "ids of tasks prerequisite to this task", + "instruction": "what you should do in this task, one short phrase or sentence", + "task_type": "type of this task, should be one of Available Task Types", + }}, + ... + ] ``` """ diff --git a/metagpt/roles/di/mgx.py b/metagpt/roles/di/mgx.py index 0fa7c77b6..9d2f182e3 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: