refactor: Refactor Message transmission & filtering

This commit is contained in:
莘权 马 2023-11-01 20:08:58 +08:00
parent 5e8ada5cff
commit 545d77ce0d
30 changed files with 658 additions and 296 deletions

View file

@ -16,9 +16,10 @@ from metagpt.llm import LLM
from metagpt.logs import logger
from metagpt.utils.common import OutputParser
from metagpt.utils.custom_decoder import CustomDecoder
from metagpt.utils.named import Named
class Action(ABC):
class Action(ABC, Named):
def __init__(self, name: str = "", context=None, llm: LLM = None):
self.name: str = name
if llm is None:

View file

@ -5,13 +5,14 @@
@Author : alexanderwu
@File : write_code.py
"""
from tenacity import retry, stop_after_attempt, wait_fixed
from metagpt.actions import WriteDesign
from metagpt.actions.action import Action
from metagpt.const import WORKSPACE_ROOT
from metagpt.logs import logger
from metagpt.schema import Message
from metagpt.utils.common import CodeParser
from tenacity import retry, stop_after_attempt, wait_fixed
PROMPT_TEMPLATE = """
NOTICE
@ -55,7 +56,8 @@ class WriteCode(Action):
if self._is_invalid(filename):
return
design = [i for i in context if i.cause_by == WriteDesign][0]
message_filter = {WriteDesign.get_class_name()}
design = [i for i in context if i.is_recipient(message_filter)][0]
ws_name = CodeParser.parse_str(block="Python package name", text=design.content)
ws_path = WORKSPACE_ROOT / ws_name
@ -74,9 +76,8 @@ class WriteCode(Action):
async def run(self, context, filename):
prompt = PROMPT_TEMPLATE.format(context=context, filename=filename)
logger.info(f'Writing {filename}..')
logger.info(f"Writing {filename}..")
code = await self.write_code(prompt)
# code_rsp = await self._aask_v1(prompt, "code_rsp", OUTPUT_MAPPING)
# self._save(context, filename, code)
return code