chore: prompt support Message type.

This commit is contained in:
刘棒棒 2023-11-22 17:56:43 +08:00
parent fa400a0b0d
commit 8ef05bb19f

View file

@ -4,6 +4,8 @@
@Author : orange-crow
@File : plan.py
"""
from typing import Union
from metagpt.actions import Action
from metagpt.prompts.plan import TASK_PLAN_SYSTEM_MSG
from metagpt.schema import Message
@ -13,8 +15,8 @@ class Plan(Action):
def __init__(self, llm=None):
super().__init__("", None, llm)
async def run(self, prompt: str, role: str = None, system_msg: str = None) -> str:
async def run(self, prompt: Union[str, Message], role: str = None, system_msg: str = None) -> str:
if role:
system_msg = TASK_PLAN_SYSTEM_MSG.format(role=role)
rsp = await self._aask(system_msg + prompt)
rsp = self._aask(system_msg + prompt.content) if isinstance(prompt, Message) else await self._aask(system_msg + prompt)
return Message(rsp, role="assistant", sent_from=self.__class__.__name__)