🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
fixbug: type error
莘权 马ffa0a6223dfc
diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.pyindex 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 asynciofrom enum import Enum-from typing import List, Tuple+from typing import Tuplefrom 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.pyindex b2caa930b..90e88303e 100644--- a/metagpt/roles/di/mgx.py+++ b/metagpt/roles/di/mgx.py@@ -2,7 +2,7 @@# @Author : stellahong ([email protected])# @Desc :import asyncio-from typing import Dict, List+from typing import Dictfrom metagpt.actions.di.detect_intent import DetectIntentfrom metagpt.logs import logger@@ -14,9 +14,9 @@ class MGX(DataInterpreter):use_intent: bool = Trueintents: 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 requirementif self.use_intent: # add modeuser_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.pyindex 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