add AttrDict

This commit is contained in:
geekan 2024-01-08 16:26:52 +08:00
parent 7ab6e43b62
commit 77938b076c
4 changed files with 32 additions and 19 deletions

View file

@ -12,8 +12,8 @@ import uuid
import pytest
from metagpt.actions import WriteDesign, WritePRD
from metagpt.config import CONFIG
from metagpt.const import PRDS_FILE_REPO
from metagpt.context import context
from metagpt.logs import logger
from metagpt.roles import Architect
from metagpt.schema import Message
@ -25,7 +25,7 @@ from tests.metagpt.roles.mock import MockMessages
async def test_architect():
# Prerequisites
filename = uuid.uuid4().hex + ".json"
await awrite(CONFIG.git_repo.workdir / PRDS_FILE_REPO / filename, data=MockMessages.prd.content)
await awrite(context.git_repo.workdir / PRDS_FILE_REPO / filename, data=MockMessages.prd.content)
role = Architect()
rsp = await role.run(with_message=Message(content="", cause_by=WritePRD))

View file

@ -12,7 +12,7 @@ from pydantic import BaseModel
from metagpt.actions.skill_action import SkillAction
from metagpt.actions.talk_action import TalkAction
from metagpt.config import CONFIG
from metagpt.context import context
from metagpt.memory.brain_memory import BrainMemory
from metagpt.roles.assistant import Assistant
from metagpt.schema import Message
@ -21,7 +21,7 @@ from metagpt.utils.common import any_to_str
@pytest.mark.asyncio
async def test_run():
CONFIG.language = "Chinese"
context.kwargs.language = "Chinese"
class Input(BaseModel):
memory: BrainMemory
@ -65,7 +65,7 @@ async def test_run():
"cause_by": any_to_str(SkillAction),
},
]
CONFIG.agent_skills = [
context.kwargs.agent_skills = [
{"id": 1, "name": "text_to_speech", "type": "builtin", "config": {}, "enabled": True},
{"id": 2, "name": "text_to_image", "type": "builtin", "config": {}, "enabled": True},
{"id": 3, "name": "ai_call", "type": "builtin", "config": {}, "enabled": True},
@ -77,8 +77,8 @@ async def test_run():
for i in inputs:
seed = Input(**i)
CONFIG.language = seed.language
CONFIG.agent_description = seed.agent_description
context.kwargs.language = seed.language
context.kwargs.agent_description = seed.agent_description
role = Assistant(language="Chinese")
role.memory = seed.memory # Restore historical conversation content.
while True:
@ -118,13 +118,7 @@ async def test_memory(memory):
assert val
await role.talk("draw apple")
agent_skills = CONFIG.agent_skills
CONFIG.agent_skills = []
try:
await role.think()
finally:
CONFIG.agent_skills = agent_skills
await role.think()
assert isinstance(role.rc.todo, TalkAction)