mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
feat: + subscribe
This commit is contained in:
parent
8572fa8ecd
commit
660f788683
3 changed files with 68 additions and 14 deletions
64
tests/metagpt/roles/test_role.py
Normal file
64
tests/metagpt/roles/test_role.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023-11-1
|
||||
@Author : mashenquan
|
||||
@File : test_role.py
|
||||
"""
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
|
||||
from metagpt.actions import Action, ActionOutput
|
||||
from metagpt.environment import Environment
|
||||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message
|
||||
|
||||
|
||||
class MockAction(Action):
|
||||
async def run(self, messages, *args, **kwargs):
|
||||
assert messages
|
||||
return ActionOutput(content=messages[-1].content, instruct_content=messages[-1])
|
||||
|
||||
|
||||
class MockRole(Role):
|
||||
def __init__(self, name="", profile="", goal="", constraints="", desc=""):
|
||||
super().__init__(name=name, profile=profile, goal=goal, constraints=constraints, desc=desc)
|
||||
self._init_actions([MockAction()])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_react():
|
||||
class Input(BaseModel):
|
||||
name: str
|
||||
profile: str
|
||||
goal: str
|
||||
constraints: str
|
||||
desc: str
|
||||
subscription: str
|
||||
|
||||
inputs = [
|
||||
{
|
||||
"name": "A",
|
||||
"profile": "Tester",
|
||||
"goal": "Test",
|
||||
"constraints": "constraints",
|
||||
"desc": "desc",
|
||||
"subscription": "start",
|
||||
}
|
||||
]
|
||||
|
||||
for i in inputs:
|
||||
seed = Input(**i)
|
||||
role = MockRole(
|
||||
name=seed.name, profile=seed.profile, goal=seed.goal, constraints=seed.constraints, desc=seed.desc
|
||||
)
|
||||
role.subscribe({seed.subscription})
|
||||
env = Environment()
|
||||
env.add_role(role)
|
||||
env.publish_message(Message(content="test", cause_by=seed.subscription))
|
||||
while not env.is_idle:
|
||||
await env.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-s"])
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/5/11 14:44
|
||||
@Author : alexanderwu
|
||||
@File : test_role.py
|
||||
"""
|
||||
from metagpt.roles import Role
|
||||
|
||||
|
||||
def test_role_desc():
|
||||
i = Role(profile='Sales', desc='Best Seller')
|
||||
assert i.profile == 'Sales'
|
||||
assert i._setting.desc == 'Best Seller'
|
||||
Loading…
Add table
Add a link
Reference in a new issue