feat: merge fixbug/geekan/v0.5-release

This commit is contained in:
莘权 马 2023-12-18 16:39:02 +08:00
commit 5593008110
7 changed files with 52 additions and 6 deletions

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023/12/18
@Author : mashenquan
@File : role_run.py
@Desc : Message type caused by `Role.run()` invocation.
"""
from metagpt.actions import Action
class RoleRun(Action):
"""Message type caused by `Role.run` invocation"""
async def run(self, *args, **kwargs):
raise NotImplementedError

View file

@ -17,12 +17,18 @@ from loguru import logger
import metagpt
OPTIONS = contextvars.ContextVar("OPTIONS")
OPTIONS = contextvars.ContextVar("OPTIONS", default={})
def get_metagpt_package_root():
"""Get the root directory of the installed package."""
package_root = Path(metagpt.__file__).parent.parent
for i in (".git", ".project_root", ".gitignore"):
if (package_root / i).exists():
break
else:
package_root = Path.cwd()
logger.info(f"Package root set to {str(package_root)}")
return package_root

View file

@ -28,6 +28,7 @@ from pydantic import BaseModel, Field
from metagpt.actions import Action, ActionOutput
from metagpt.actions.action_node import ActionNode
from metagpt.actions.role_run import RoleRun
from metagpt.llm import LLM, HumanProvider
from metagpt.logs import logger
from metagpt.memory import Memory
@ -317,7 +318,9 @@ class Role:
old_messages = [] if ignore_memory else self._rc.memory.get()
self._rc.memory.add_batch(news)
# Filter out messages of interest.
self._rc.news = [n for n in news if n.cause_by in self._rc.watch and n not in old_messages]
watch = self._rc.watch or set()
watch.add(any_to_str(RoleRun))
self._rc.news = [n for n in news if n.cause_by in watch and n not in old_messages]
# Design Rules:
# If you need to further categorize Message objects, you can do so using the Message.set_meta function.
@ -397,6 +400,8 @@ class Role:
msg = with_message
elif isinstance(with_message, list):
msg = Message("\n".join(with_message))
if not msg.cause_by:
msg.cause_by = RoleRun
self.put_message(msg)
if not await self._observe():

View file

@ -3,10 +3,12 @@
"""
@Time : 2023/5/12 00:30
@Author : alexanderwu
@File : software_company.py
@File : team.py
@Modified By: mashenquan, 2023/11/27. Add an archiving operation after completing the project, as specified in
Section 2.2.3.3 of RFC 135.
"""
import warnings
from pydantic import BaseModel, Field
from metagpt.actions import UserRequirement
@ -50,7 +52,7 @@ class Team(BaseModel):
)
def run_project(self, idea, send_to: str = ""):
"""Start a project from publishing user requirement."""
"""Run a project from publishing user requirement."""
self.idea = idea
# Human requirement.
@ -59,6 +61,19 @@ class Team(BaseModel):
peekable=False,
)
def start_project(self, idea, send_to: str = ""):
"""
Deprecated: This method will be removed in the future.
Please use the `run_project` method instead.
"""
warnings.warn(
"The 'start_project' method is deprecated and will be removed in the future. "
"Please use the 'run_project' method instead.",
DeprecationWarning,
stacklevel=2,
)
return self.run_project(idea=idea, send_to=send_to)
def _save(self):
logger.info(self.json(ensure_ascii=False))