mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
resolve conflicts
This commit is contained in:
parent
20a137ef45
commit
0c6d4ae53a
4 changed files with 36 additions and 35 deletions
|
|
@ -6,22 +6,32 @@
|
|||
@File : environment.py
|
||||
"""
|
||||
import asyncio
|
||||
from queue import Queue
|
||||
|
||||
from typing import Iterable
|
||||
|
||||
from metagpt.manager import Manager
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
BaseSettings,
|
||||
PyObject,
|
||||
RedisDsn,
|
||||
PostgresDsn,
|
||||
Field,
|
||||
)
|
||||
|
||||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message
|
||||
from metagpt.memory import Memory
|
||||
|
||||
|
||||
class Environment:
|
||||
class Environment(BaseModel):
|
||||
"""环境,承载一批角色,角色可以向环境发布消息,可以被其他角色观察到"""
|
||||
def __init__(self):
|
||||
self.roles: dict[str, Role] = {}
|
||||
# self.message_queue = Queue()
|
||||
self.memory = Memory()
|
||||
self.history = ''
|
||||
|
||||
roles: dict[str, Role] = Field(default_factory=dict)
|
||||
memory: Memory = Field(default_factory=Memory)
|
||||
history: str = Field(default='')
|
||||
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def add_role(self, role: Role):
|
||||
"""增加一个在当前环境的Role"""
|
||||
|
|
@ -33,10 +43,6 @@ class Environment:
|
|||
for role in roles:
|
||||
self.add_role(role)
|
||||
|
||||
def set_manager(self, manager):
|
||||
"""设置一个当前环境的管理员"""
|
||||
self.manager = manager
|
||||
|
||||
def publish_message(self, message: Message):
|
||||
"""向当前环境发布信息"""
|
||||
# self.message_queue.put(message)
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@
|
|||
@File : role.py
|
||||
"""
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass, asdict, field
|
||||
from typing import Type, Iterable
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from metagpt.logs import logger
|
||||
|
||||
# from metagpt.environment import Environment
|
||||
|
|
@ -45,8 +46,7 @@ ROLE_TEMPLATE = """Your response should be based on the previous conversation hi
|
|||
"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class RoleSetting:
|
||||
class RoleSetting(BaseModel):
|
||||
"""角色设定"""
|
||||
name: str
|
||||
profile: str
|
||||
|
|
@ -61,14 +61,16 @@ class RoleSetting:
|
|||
return self.__str__()
|
||||
|
||||
|
||||
@dataclass
|
||||
class RoleContext:
|
||||
class RoleContext(BaseModel):
|
||||
"""角色运行时上下文"""
|
||||
env: 'Environment' = field(default=None)
|
||||
memory: Memory = field(default_factory=Memory)
|
||||
state: int = field(default=0)
|
||||
todo: Action = field(default=None)
|
||||
watch: set[Type[Action]] = field(default_factory=set)
|
||||
env: 'Environment' = Field(default=None)
|
||||
memory: Memory = Field(default_factory=Memory)
|
||||
state: int = Field(default=0)
|
||||
todo: Action = Field(default=None)
|
||||
watch: set[Type[Action]] = Field(default_factory=set)
|
||||
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
@property
|
||||
def important_memory(self) -> list[Message]:
|
||||
|
|
@ -85,7 +87,7 @@ class Role:
|
|||
|
||||
def __init__(self, name="", profile="", goal="", constraints="", desc=""):
|
||||
self._llm = LLM()
|
||||
self._setting = RoleSetting(name, profile, goal, constraints, desc)
|
||||
self._setting = RoleSetting(name=name, profile=profile, goal=goal, constraints=constraints, desc=desc)
|
||||
self._states = []
|
||||
self._actions = []
|
||||
self._rc = RoleContext()
|
||||
|
|
@ -127,7 +129,7 @@ class Role:
|
|||
"""获取角色前缀"""
|
||||
if self._setting.desc:
|
||||
return self._setting.desc
|
||||
return PREFIX_TEMPLATE.format(**asdict(self._setting))
|
||||
return PREFIX_TEMPLATE.format(**self._setting.dict())
|
||||
|
||||
async def _think(self) -> None:
|
||||
"""思考要做什么,决定下一步的action"""
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
@Author : alexanderwu
|
||||
@File : software_company.py
|
||||
"""
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.actions import BossRequirement
|
||||
|
|
@ -21,9 +21,9 @@ class SoftwareCompany(BaseModel):
|
|||
Software Company: Possesses a team, SOP (Standard Operating Procedures), and a platform for instant messaging,
|
||||
dedicated to writing executable code.
|
||||
"""
|
||||
environment: Environment = Environment()
|
||||
investment: float = 0
|
||||
idea: str = ""
|
||||
environment: Environment = Field(default_factory=Environment)
|
||||
investment: float = Field(default=10.0)
|
||||
idea: str = Field(default="")
|
||||
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
|
|
|
|||
|
|
@ -3,20 +3,13 @@ loguru
|
|||
openai
|
||||
pyperclip==1.8.2
|
||||
pytest==7.2.2
|
||||
quart
|
||||
aiohttp
|
||||
gunicorn
|
||||
gevent
|
||||
duckduckgo-search
|
||||
openapi_schema_pydantic
|
||||
numexpr
|
||||
google-search-results
|
||||
langchain
|
||||
faiss-cpu
|
||||
tiktoken
|
||||
pytest-xdist
|
||||
socksipy-branch
|
||||
oauth2client
|
||||
google-api-python-client
|
||||
meilisearch
|
||||
azure-cognitiveservices-speech
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue