From eec69e64a3131c9c58b38920906a2fd4f0477dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Sun, 7 Apr 2024 13:01:03 +0800 Subject: [PATCH 1/6] fixbug: type error --- metagpt/actions/di/detect_intent.py | 2 ++ metagpt/roles/di/mgx.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.py index 8f56f4ae8..d41317321 100644 --- a/metagpt/actions/di/detect_intent.py +++ b/metagpt/actions/di/detect_intent.py @@ -90,6 +90,8 @@ You should follow the following Standard Operating Procedure: class DetectIntent(Action): async def run(self, user_requirement: str) -> Tuple[str, str]: + if not isinstance(user_requirement, str): + raise ValueError(f"str type error: {user_requirement}") intentions = "\n".join([f"{si.type_name}: {si.value.description}" for si in SOPItem]) prompt = DETECT_PROMPT.format(user_requirement=user_requirement, intentions=intentions) diff --git a/metagpt/roles/di/mgx.py b/metagpt/roles/di/mgx.py index b2caa930b..33377e5f1 100644 --- a/metagpt/roles/di/mgx.py +++ b/metagpt/roles/di/mgx.py @@ -16,7 +16,8 @@ class MGX(DataInterpreter): async def _detect_intent(self, user_msgs: List[Message] = None, **kwargs): todo = DetectIntent(context=self.context) - request_with_sop, sop_type = await todo.run(user_msgs) + user_requirement = "\n".join([f"> {i.role}: {i.content}" for i in user_msgs]) + request_with_sop, sop_type = await todo.run(user_requirement) logger.info(f"{sop_type} {request_with_sop}") return request_with_sop From ef3563500f9aa409f7a35df89ebed49e014d0185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Sun, 7 Apr 2024 13:12:34 +0800 Subject: [PATCH 2/6] fixbug: type error --- metagpt/actions/di/detect_intent.py | 24 ++++--------------- metagpt/roles/di/mgx.py | 3 +-- .../metagpt/actions/di/test_detect_intent.py | 3 ++- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.py index d41317321..ba42660b6 100644 --- a/metagpt/actions/di/detect_intent.py +++ b/metagpt/actions/di/detect_intent.py @@ -1,12 +1,12 @@ from __future__ import annotations -import asyncio from enum import Enum -from typing import Tuple +from typing import List, Tuple from pydantic import BaseModel from metagpt.actions import Action +from metagpt.schema import Message class SOPItemDef(BaseModel): @@ -89,9 +89,8 @@ You should follow the following Standard Operating Procedure: class DetectIntent(Action): - async def run(self, user_requirement: str) -> Tuple[str, str]: - if not isinstance(user_requirement, str): - raise ValueError(f"str type error: {user_requirement}") + async def run(self, user_msgs: List[Message]) -> Tuple[str, str]: + user_requirement = "\n".join([f"> {i.role}: {i.content}" for i in user_msgs]) intentions = "\n".join([f"{si.type_name}: {si.value.description}" for si in SOPItem]) prompt = DETECT_PROMPT.format(user_requirement=user_requirement, intentions=intentions) @@ -105,18 +104,3 @@ class DetectIntent(Action): ) return req_with_sop, sop_type - - -async def main(): - # Example usage of the DetectIntent action - user_requirements = ["Develop a 2048 game.", "Run data analysis on sklearn wine dataset"] - detect_intent = DetectIntent() - - for user_requirement in user_requirements: - req_with_sop, sop_type = await detect_intent.run(user_requirement) - print(req_with_sop) - print(f"Detected SOP Type: {sop_type}") - - -if __name__ == "__main__": - asyncio.run(main()) diff --git a/metagpt/roles/di/mgx.py b/metagpt/roles/di/mgx.py index 33377e5f1..b2caa930b 100644 --- a/metagpt/roles/di/mgx.py +++ b/metagpt/roles/di/mgx.py @@ -16,8 +16,7 @@ class MGX(DataInterpreter): async def _detect_intent(self, user_msgs: List[Message] = None, **kwargs): todo = DetectIntent(context=self.context) - user_requirement = "\n".join([f"> {i.role}: {i.content}" for i in user_msgs]) - request_with_sop, sop_type = await todo.run(user_requirement) + request_with_sop, sop_type = await todo.run(user_msgs) logger.info(f"{sop_type} {request_with_sop}") return request_with_sop diff --git a/tests/metagpt/actions/di/test_detect_intent.py b/tests/metagpt/actions/di/test_detect_intent.py index 7c9cf9eba..dfb25c343 100644 --- a/tests/metagpt/actions/di/test_detect_intent.py +++ b/tests/metagpt/actions/di/test_detect_intent.py @@ -1,6 +1,7 @@ import pytest from metagpt.actions.di.detect_intent import DetectIntent +from metagpt.schema import Message SOFTWARE_DEV_REQ1 = """ I'd like to create a personalized website that features the 'Game of Life' simulation. @@ -51,5 +52,5 @@ git clone 'https://github.com/spec-first/connexion' and format to MetaGPT projec ) async def test_detect_intent(requirement, expected_intent_type): di = DetectIntent() - _, intent_type = await di.run(requirement) + _, intent_type = await di.run([Message(role="user", content=requirement)]) assert intent_type == expected_intent_type From ffa0a6223dfcb1a12e8ea5f5fa0acfedfafd59bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Sun, 7 Apr 2024 13:27:10 +0800 Subject: [PATCH 3/6] fixbug: type error --- metagpt/actions/di/detect_intent.py | 23 ++++++++++++++++--- metagpt/roles/di/mgx.py | 8 +++---- .../metagpt/actions/di/test_detect_intent.py | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.py index ba42660b6..a09541cf6 100644 --- a/metagpt/actions/di/detect_intent.py +++ b/metagpt/actions/di/detect_intent.py @@ -1,7 +1,8 @@ from __future__ import annotations +import asyncio from enum import Enum -from typing import List, Tuple +from typing import Tuple from pydantic import BaseModel @@ -89,8 +90,9 @@ You should follow the following Standard Operating Procedure: class DetectIntent(Action): - async def run(self, user_msgs: List[Message]) -> Tuple[str, str]: - user_requirement = "\n".join([f"> {i.role}: {i.content}" for i in user_msgs]) + async def run(self, with_message: Message, **kwargs) -> Tuple[str, str]: + ref_content = with_message.content.replace("\n", "\n> ") + user_requirement = f"> {with_message.role}: {ref_content}" intentions = "\n".join([f"{si.type_name}: {si.value.description}" for si in SOPItem]) prompt = DETECT_PROMPT.format(user_requirement=user_requirement, intentions=intentions) @@ -104,3 +106,18 @@ class DetectIntent(Action): ) return req_with_sop, sop_type + + +async def main(): + # Example usage of the DetectIntent action + user_requirements = ["Develop a 2048 game.", "Run data analysis on sklearn wine dataset"] + detect_intent = DetectIntent() + + for user_requirement in user_requirements: + req_with_sop, sop_type = await detect_intent.run(Message(role="user", content=user_requirement)) + print(req_with_sop) + print(f"Detected SOP Type: {sop_type}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/metagpt/roles/di/mgx.py b/metagpt/roles/di/mgx.py index b2caa930b..90e88303e 100644 --- a/metagpt/roles/di/mgx.py +++ b/metagpt/roles/di/mgx.py @@ -2,7 +2,7 @@ # @Author : stellahong (stellahong@fuzhi.ai) # @Desc : import asyncio -from typing import Dict, List +from typing import Dict from metagpt.actions.di.detect_intent import DetectIntent from metagpt.logs import logger @@ -14,9 +14,9 @@ class MGX(DataInterpreter): use_intent: bool = True intents: Dict = {} - async def _detect_intent(self, user_msgs: List[Message] = None, **kwargs): + async def _detect_intent(self, user_msg: Message = None, **kwargs): todo = DetectIntent(context=self.context) - request_with_sop, sop_type = await todo.run(user_msgs) + request_with_sop, sop_type = await todo.run(user_msg) logger.info(f"{sop_type} {request_with_sop}") return request_with_sop @@ -27,7 +27,7 @@ class MGX(DataInterpreter): goal = self.rc.memory.get()[-1].content # retreive latest user requirement if self.use_intent: # add mode user_message = Message(content=goal, role="user") - goal = await self._detect_intent(user_msgs=[user_message]) + goal = await self._detect_intent(user_message) logger.info(f"Goal is {goal}") await self.planner.update_plan(goal=goal) diff --git a/tests/metagpt/actions/di/test_detect_intent.py b/tests/metagpt/actions/di/test_detect_intent.py index dfb25c343..e555680ef 100644 --- a/tests/metagpt/actions/di/test_detect_intent.py +++ b/tests/metagpt/actions/di/test_detect_intent.py @@ -52,5 +52,5 @@ git clone 'https://github.com/spec-first/connexion' and format to MetaGPT projec ) async def test_detect_intent(requirement, expected_intent_type): di = DetectIntent() - _, intent_type = await di.run([Message(role="user", content=requirement)]) + _, intent_type = await di.run(Message(role="user", content=requirement)) assert intent_type == expected_intent_type From b91905ce581dd91f86039d82e64138394530727b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Sun, 7 Apr 2024 13:28:46 +0800 Subject: [PATCH 4/6] fixbug: type error --- metagpt/roles/di/mgx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metagpt/roles/di/mgx.py b/metagpt/roles/di/mgx.py index 90e88303e..0034dfe93 100644 --- a/metagpt/roles/di/mgx.py +++ b/metagpt/roles/di/mgx.py @@ -14,7 +14,7 @@ class MGX(DataInterpreter): use_intent: bool = True intents: Dict = {} - async def _detect_intent(self, user_msg: Message = None, **kwargs): + async def _detect_intent(self, user_msg: Message, **kwargs): todo = DetectIntent(context=self.context) request_with_sop, sop_type = await todo.run(user_msg) logger.info(f"{sop_type} {request_with_sop}") From ada3c1554ce58623a00320d0a57934a79a864467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Sun, 7 Apr 2024 13:29:07 +0800 Subject: [PATCH 5/6] fixbug: type error --- metagpt/roles/di/mgx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metagpt/roles/di/mgx.py b/metagpt/roles/di/mgx.py index 0034dfe93..1002a559c 100644 --- a/metagpt/roles/di/mgx.py +++ b/metagpt/roles/di/mgx.py @@ -14,7 +14,7 @@ class MGX(DataInterpreter): use_intent: bool = True intents: Dict = {} - async def _detect_intent(self, user_msg: Message, **kwargs): + async def _detect_intent(self, user_msg: Message): todo = DetectIntent(context=self.context) request_with_sop, sop_type = await todo.run(user_msg) logger.info(f"{sop_type} {request_with_sop}") From 4455b298fcaf03f12dc079490490bd755430ae94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Sun, 7 Apr 2024 13:39:19 +0800 Subject: [PATCH 6/6] fixbug: type error --- metagpt/actions/di/detect_intent.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.py index a09541cf6..9109c01bb 100644 --- a/metagpt/actions/di/detect_intent.py +++ b/metagpt/actions/di/detect_intent.py @@ -91,8 +91,7 @@ You should follow the following Standard Operating Procedure: class DetectIntent(Action): async def run(self, with_message: Message, **kwargs) -> Tuple[str, str]: - ref_content = with_message.content.replace("\n", "\n> ") - user_requirement = f"> {with_message.role}: {ref_content}" + user_requirement = with_message.content intentions = "\n".join([f"{si.type_name}: {si.value.description}" for si in SOPItem]) prompt = DETECT_PROMPT.format(user_requirement=user_requirement, intentions=intentions)