MetaGPT

Форк
0
/
test_environment.py 
64 строки · 2.0 Кб
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
"""
4
@Time    : 2023/5/12 00:47
5
@Author  : alexanderwu
6
@File    : test_environment.py
7
"""
8

9
from pathlib import Path
10

11
import pytest
12

13
from metagpt.actions import UserRequirement
14
from metagpt.environment import Environment
15
from metagpt.logs import logger
16
from metagpt.roles import Architect, ProductManager, Role
17
from metagpt.schema import Message
18

19
serdeser_path = Path(__file__).absolute().parent.joinpath("../data/serdeser_storage")
20

21

22
@pytest.fixture
23
def env():
24
    return Environment()
25

26

27
def test_add_role(env: Environment):
28
    role = ProductManager(
29
        name="Alice", profile="product manager", goal="create a new product", constraints="limited resources"
30
    )
31
    env.add_role(role)
32
    assert env.get_role(str(role._setting)) == role
33

34

35
def test_get_roles(env: Environment):
36
    role1 = Role(name="Alice", profile="product manager", goal="create a new product", constraints="limited resources")
37
    role2 = Role(name="Bob", profile="engineer", goal="develop the new product", constraints="short deadline")
38
    env.add_role(role1)
39
    env.add_role(role2)
40
    roles = env.get_roles()
41
    assert roles == {role1.profile: role1, role2.profile: role2}
42

43

44
@pytest.mark.asyncio
45
async def test_publish_and_process_message(env: Environment):
46
    if env.context.git_repo:
47
        env.context.git_repo.delete_repository()
48
        env.context.git_repo = None
49

50
    product_manager = ProductManager(name="Alice", profile="Product Manager", goal="做AI Native产品", constraints="资源有限")
51
    architect = Architect(
52
        name="Bob", profile="Architect", goal="设计一个可用、高效、较低成本的系统,包括数据结构与接口", constraints="资源有限,需要节省成本"
53
    )
54

55
    env.add_roles([product_manager, architect])
56

57
    env.publish_message(Message(role="User", content="需要一个基于LLM做总结的搜索引擎", cause_by=UserRequirement))
58
    await env.run(k=2)
59
    logger.info(f"{env.history=}")
60
    assert len(env.history) > 10
61

62

63
if __name__ == "__main__":
64
    pytest.main([__file__, "-s"])
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.