support spark

This commit is contained in:
geekan 2024-01-11 20:51:27 +08:00
parent b9b268ad8b
commit f59449d5d2
5 changed files with 50 additions and 8 deletions

View file

@ -1,9 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Desc : the unittest of spark api
from pathlib import Path
import pytest
from metagpt.config2 import Config
from metagpt.provider.spark_api import GetMessageFromWeb, SparkLLM
from tests.metagpt.provider.mock_llm_config import mock_llm_config
@ -33,6 +35,14 @@ def mock_spark_get_msg_from_web_run(self) -> str:
return resp_content
@pytest.mark.asyncio
async def test_spark_aask():
llm = SparkLLM(Config.model_validate_yaml(Path.home() / ".metagpt" / "spark.yaml").llm)
resp = await llm.aask("Hello!")
print(resp)
@pytest.mark.asyncio
async def test_spark_acompletion(mocker):
mocker.patch("metagpt.provider.spark_api.GetMessageFromWeb.run", mock_spark_get_msg_from_web_run)

View file

@ -5,10 +5,15 @@
@Author : alexanderwu
@File : test_context_mixin.py
"""
import pytest
from pydantic import BaseModel
from metagpt.actions import Action
from metagpt.config2 import Config
from metagpt.context_mixin import ContextMixin
from metagpt.environment import Environment
from metagpt.roles import Role
from metagpt.team import Team
from tests.metagpt.provider.mock_llm_config import (
mock_llm_config,
mock_llm_config_proxy,
@ -91,3 +96,27 @@ def test_config_mixin_4_multi_inheritance_override_config():
print(obj.__dict__.keys())
assert "private_config" in obj.__dict__.keys()
assert obj.llm.model == "mock_zhipu_model"
@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")
biden = Role(
name="Alex", profile="Democratic candidate", goal="Win the election", actions=[action1], watch=[action2]
)
trump = 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=[biden, trump])
print(action1.llm.system_prompt)
print(action2.llm.system_prompt)
print(biden.llm.system_prompt)
print(trump.llm.system_prompt)
history = await team.run(idea="Topic: climate change. Under 80 words per message.", send_to="Alex", n_round=3)
assert "Alex" in history