mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-15 11:02:36 +02:00
refine code
This commit is contained in:
parent
c9e05a2186
commit
df9d5158ec
2 changed files with 7 additions and 6 deletions
|
|
@ -158,6 +158,7 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):
|
|||
|
||||
@staticmethod
|
||||
def pydantic_rebuild_model():
|
||||
"""Rebuild model to avoid `RecursionError: maximum recursion depth exceeded in comparison`"""
|
||||
from metagpt.environment import Environment
|
||||
|
||||
Environment
|
||||
|
|
@ -165,9 +166,11 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):
|
|||
|
||||
@property
|
||||
def todo(self) -> Action:
|
||||
"""Get action to do"""
|
||||
return self.rc.todo
|
||||
|
||||
def set_todo(self, value: Optional[Action]):
|
||||
"""Set action to do and update context"""
|
||||
if value:
|
||||
value.g_context = self.context
|
||||
self.rc.todo = value
|
||||
|
|
@ -181,6 +184,7 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):
|
|||
|
||||
@property
|
||||
def git_repo(self):
|
||||
"""Git repo"""
|
||||
return self.context.git_repo
|
||||
|
||||
@git_repo.setter
|
||||
|
|
@ -189,6 +193,7 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):
|
|||
|
||||
@property
|
||||
def src_workspace(self):
|
||||
"""Source workspace under git repo"""
|
||||
return self.context.src_workspace
|
||||
|
||||
@src_workspace.setter
|
||||
|
|
@ -197,6 +202,7 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):
|
|||
|
||||
@property
|
||||
def prompt_schema(self):
|
||||
"""Prompt schema: json/markdown"""
|
||||
return self.config.prompt_schema
|
||||
|
||||
@property
|
||||
|
|
@ -308,11 +314,6 @@ class Role(SerializationMixin, ConfigMixin, BaseModel):
|
|||
env.set_addresses(self, self.addresses)
|
||||
self.llm.system_prompt = self._get_prefix()
|
||||
|
||||
@property
|
||||
def action_count(self):
|
||||
"""Return number of action"""
|
||||
return len(self.actions)
|
||||
|
||||
def _get_prefix(self):
|
||||
"""Get the role prefix"""
|
||||
if self.desc:
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ async def test_send_to():
|
|||
def test_init_action():
|
||||
role = Role()
|
||||
role.add_actions([MockAction, MockAction])
|
||||
assert role.action_count == 2
|
||||
assert len(role.actions) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue