From 1545a702ccd4610c14acd818ae8fc6a19fd8d84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Sat, 26 Aug 2023 22:28:41 +0800 Subject: [PATCH] fixbug: skill_yaml_file_name --- metagpt/actions/meta_action.py | 64 ---------------------------------- metagpt/roles/assistant.py | 5 ++- 2 files changed, 4 insertions(+), 65 deletions(-) delete mode 100644 metagpt/actions/meta_action.py diff --git a/metagpt/actions/meta_action.py b/metagpt/actions/meta_action.py deleted file mode 100644 index 4c52e7cfd..000000000 --- a/metagpt/actions/meta_action.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" -@Time : 2023/8/7 -@Author : mashenquan -@File : meta_action.py -@Desc : I am attempting to incorporate certain symbol concepts from UML into MetaGPT, enabling it to have the - ability to freely construct flows through symbol concatenation. Simultaneously, I am also striving to - make these symbols configurable and standardized, making the process of building flows more convenient. - For more about `fork` node in activity diagrams, see: `https://www.uml-diagrams.org/activity-diagrams.html` - This file defines a meta action capable of generating arbitrary actions at runtime based on a - configuration file. -""" - -from typing import Type - -from metagpt.actions import Action -from metagpt.logs import logger -from metagpt.roles.uml_meta_role_options import MetaActionOptions -from metagpt.schema import Message - - -class MetaAction(Action): - def __init__(self, options, action_options: MetaActionOptions, llm=None, **kwargs): - super(MetaAction, self).__init__(options=options, - name=action_options.name, - context=kwargs.get("context"), - llm=llm) - self.prompt = action_options.format_prompt(**kwargs) - self.action_options = action_options - self.kwargs = kwargs - - def __str__(self): - """Return `topic` value when str()""" - return self.action_options.topic - - def __repr__(self): - """Show `topic` value when debug""" - return self.action_options.topic - - async def run(self, messages, *args, **kwargs): - if len(messages) < 1 or not isinstance(messages[0], Message): - raise ValueError("Invalid args, a tuple of List[Message] is expected") - - logger.debug(self.prompt) - rsp = await self._aask(prompt=self.prompt) - logger.debug(rsp) - self._set_result(rsp) - return self.rsp - - def _set_result(self, rsp): - if self.action_options.rsp_begin_tag and self.action_options.rsp_begin_tag in rsp: - ix = rsp.index(self.action_options.rsp_begin_tag) - rsp = rsp[ix + len(self.action_options.rsp_begin_tag):] - if self.action_options.rsp_end_tag and self.action_options.rsp_end_tag in rsp: - ix = rsp.index(self.action_options.rsp_end_tag) - rsp = rsp[0:ix] - self.rsp = rsp.strip() - - @staticmethod - def get_action_type(topic: str): - """Create a runtime :class:`Action` subclass""" - action_type: Type["Action"] = type(topic, (Action,), {"name": topic}) - return action_type diff --git a/metagpt/roles/assistant.py b/metagpt/roles/assistant.py index c001d69f0..a3af715e3 100644 --- a/metagpt/roles/assistant.py +++ b/metagpt/roles/assistant.py @@ -14,6 +14,7 @@ """ import asyncio +from pathlib import Path from metagpt.actions import ActionOutput from metagpt.actions.skill_action import SkillAction, ArgumentsParingAction @@ -29,6 +30,7 @@ from metagpt.schema import Message DEFAULT_MAX_TOKENS = 1500 COMMAND_TOKENS = 500 BRAIN_MEMORY = "BRAIN_MEMORY" +SKILL_PATH = "SKILL_PATH" class Assistant(Role): @@ -40,7 +42,8 @@ class Assistant(Role): goal=goal, constraints=constraints, desc=desc, *args, **kwargs) brain_memory = options.get(BRAIN_MEMORY) self.memory = BrainMemory(**brain_memory) if brain_memory else BrainMemory() - self.skills = SkillLoader() + skill_path = Path(options.get(SKILL_PATH)) if options.get(SKILL_PATH) else None + self.skills = SkillLoader(skill_yaml_file_name=skill_path) async def think(self) -> bool: """Everything will be done part by part."""