mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-24 14:15:17 +02:00
add test config
This commit is contained in:
parent
8ddd17da28
commit
0f0ef86b26
2 changed files with 13 additions and 1 deletions
|
|
@ -43,11 +43,14 @@ class AttrDict(BaseModel):
|
|||
|
||||
|
||||
class LLMMixin:
|
||||
"""Mixin class for LLM"""
|
||||
|
||||
config: Optional[Config] = None
|
||||
llm_config: Optional[LLMConfig] = None
|
||||
_llm_instance: Optional[BaseLLM] = None
|
||||
|
||||
def use_llm(self, name: Optional[str] = None, provider: LLMType = LLMType.OPENAI):
|
||||
"""Use a LLM provider"""
|
||||
# 更新LLM配置
|
||||
self.llm_config = self.config.get_llm_config(name, provider)
|
||||
# 重置LLM实例
|
||||
|
|
@ -55,7 +58,9 @@ class LLMMixin:
|
|||
|
||||
@property
|
||||
def llm(self) -> BaseLLM:
|
||||
# 实例化LLM,如果尚未实例化
|
||||
"""Return the LLM instance"""
|
||||
if not self.llm_config:
|
||||
self.use_llm()
|
||||
if not self._llm_instance and self.llm_config:
|
||||
self._llm_instance = create_llm_instance(self.llm_config)
|
||||
return self._llm_instance
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
from metagpt.config2 import Config, config
|
||||
from metagpt.configs.llm_config import LLMType
|
||||
from tests.metagpt.provider.mock_llm_config import mock_llm_config
|
||||
|
||||
|
||||
def test_config_1():
|
||||
|
|
@ -19,3 +20,9 @@ def test_config_1():
|
|||
|
||||
def test_config_2():
|
||||
assert config == Config.default()
|
||||
|
||||
|
||||
def test_config_from_dict():
|
||||
cfg = Config(llm={"default": mock_llm_config})
|
||||
assert cfg
|
||||
assert cfg.llm["default"].api_key == "mock_api_key"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue