mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-27 14:25:20 +02:00
fixbug: type error
This commit is contained in:
parent
eec69e64a3
commit
ef3563500f
3 changed files with 7 additions and 23 deletions
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue