mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-26 15:49:42 +02:00
test for mixin
This commit is contained in:
parent
784732093e
commit
312d327d55
6 changed files with 41 additions and 21 deletions
|
|
@ -1,7 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : the unittest of spark api
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -37,7 +36,7 @@ def mock_spark_get_msg_from_web_run(self) -> str:
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_spark_aask():
|
||||
llm = SparkLLM(Config.model_validate_yaml(Path.home() / ".metagpt" / "spark.yaml").llm)
|
||||
llm = SparkLLM(Config.from_home("spark.yaml").llm)
|
||||
|
||||
resp = await llm.aask("Hello!")
|
||||
print(resp)
|
||||
|
|
|
|||
|
|
@ -99,17 +99,30 @@ def test_config_mixin_4_multi_inheritance_override_config():
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_debate_two_roles():
|
||||
config = Config.default()
|
||||
config.llm.model = "gpt-4-1106-preview"
|
||||
action1 = Action(config=config, name="AlexSay", instruction="Say your opinion with emotion and don't repeat it")
|
||||
action2 = Action(name="BobSay", instruction="Say your opinion with emotion and don't repeat it")
|
||||
alex = Role(
|
||||
name="Alex", profile="Democratic candidate", goal="Win the election", actions=[action1], watch=[action2]
|
||||
)
|
||||
bob = Role(name="Bob", profile="Republican candidate", goal="Win the election", actions=[action2], watch=[action1])
|
||||
env = Environment(desc="US election live broadcast")
|
||||
team = Team(investment=10.0, env=env, roles=[alex, bob])
|
||||
async def test_config_priority():
|
||||
"""If action's config is set, then its llm will be set, otherwise, it will use the role's llm"""
|
||||
gpt4t = Config.from_home("gpt-4-1106-preview.yaml")
|
||||
gpt35 = Config.default()
|
||||
gpt4 = Config.default()
|
||||
gpt4.llm.model = "gpt-4-0613"
|
||||
|
||||
history = await team.run(idea="Topic: climate change. Under 80 words per message.", send_to="Alex", n_round=3)
|
||||
assert "Alex" in history
|
||||
a1 = Action(config=gpt4t, name="Say", instruction="Say your opinion with emotion and don't repeat it")
|
||||
a2 = Action(name="Say", instruction="Say your opinion with emotion and don't repeat it")
|
||||
a3 = Action(name="Vote", instruction="Vote for the candidate, and say why you vote for him/her")
|
||||
|
||||
# it will not work for a1 because the config is already set
|
||||
A = Role(name="A", profile="Democratic candidate", goal="Win the election", actions=[a1], watch=[a2], config=gpt4)
|
||||
# it will work for a2 because the config is not set
|
||||
B = Role(name="B", profile="Republican candidate", goal="Win the election", actions=[a2], watch=[a1], config=gpt4)
|
||||
# ditto
|
||||
C = Role(name="C", profile="Voter", goal="Vote for the candidate", actions=[a3], watch=[a1, a2], config=gpt35)
|
||||
|
||||
env = Environment(desc="US election live broadcast")
|
||||
Team(investment=10.0, env=env, roles=[A, B, C])
|
||||
|
||||
assert a1.llm.model == "gpt-4-1106-preview"
|
||||
assert a2.llm.model == "gpt-4-0613"
|
||||
assert a3.llm.model == "gpt-3.5-turbo-1106"
|
||||
|
||||
# history = await team.run(idea="Topic: climate change. Under 80 words per message.", send_to="a1", n_round=3)
|
||||
# assert "Alex" in history
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue