feat: +software_development_intent_detect

This commit is contained in:
莘权 马 2024-03-29 21:46:46 +08:00
parent b029a1996a
commit a7b4af738a
7 changed files with 165 additions and 485 deletions

View file

@ -6,7 +6,11 @@ This script defines tools for dialog.
from typing import List
from metagpt.actions.intent_detect import IntentDetect, IntentDetectResult
from metagpt.actions.intent_detect import (
IntentDetect,
IntentDetectResult,
LightIntentDetect,
)
from metagpt.context import Context
from metagpt.schema import Message
from metagpt.tools.tool_registry import register_tool
@ -74,3 +78,39 @@ async def intent_detect(messages: List[Message]) -> IntentDetectResult:
action = IntentDetect(context=ctx)
await action.run(messages)
return action.result
@register_tool(tags=["dialog", "software development intent detect"])
async def software_development_intent_detect(messages: List[Message]) -> List[str]:
"""Detects software development intent from a list of dialog messages.
Args:
messages (List[Message]): A list of dialog messages.
Returns:
IntentDetectResult: The result of intent detection.
Example:
>>> # Create messages
>>> dialog = [
>>> {"role":"user", "content":"user queries ..."},
>>> {"role":"assistant", "content": "assistant answers ..."},
>>> ...
>>> ]
>>> from metagpt.schema import Message
>>> messages = [Message.model_validate(i) for i in dialog]
>>> result = await software_development_intent_detect(messages)
>>> print(result)
[
"Writes a PRD based on software requirements.",
"Writes a design to the project repository, based on the PRD of the project.",
"Writes a project plan to the project repository, based on the design of the project.",
"Writes codes to the project repository, based on the project plan of the project.",
"Run QA test on the project repository.",
"Stage and commit changes for the project repository using Git."
]
"""
ctx = Context()
action = LightIntentDetect(context=ctx)
await action.run(messages)
return action.result[0].sop if action.result else []