Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
geekan committed Jul 12, 2023
1 parent 20a137e commit 0c6d4ae
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
30 changes: 18 additions & 12 deletions metagpt/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -33,10 +43,6 @@ def add_roles(self, roles: Iterable[Role]):
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)
Expand Down
26 changes: 14 additions & 12 deletions metagpt/roles/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,8 +46,7 @@
"""


@dataclass
class RoleSetting:
class RoleSetting(BaseModel):
"""角色设定"""
name: str
profile: str
Expand All @@ -61,14 +61,16 @@ def __repr__(self):
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]:
Expand All @@ -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()
Expand Down Expand Up @@ -127,7 +129,7 @@ def _get_prefix(self):
"""获取角色前缀"""
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"""
Expand Down
8 changes: 4 additions & 4 deletions metagpt/software_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c6d4ae

Please sign in to comment.