🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
add test config
geekan0f0ef86b2620
diff --git a/metagpt/context.py b/metagpt/context.pyindex 3505614bb..eb46ab19b 100644--- a/metagpt/context.py+++ b/metagpt/context.py@@ -43,11 +43,14 @@ class AttrDict(BaseModel):class LLMMixin:+ """Mixin class for LLM"""+config: Optional[Config] = Nonellm_config: Optional[LLMConfig] = None_llm_instance: Optional[BaseLLM] = Nonedef 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:@propertydef 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_instancediff --git a/tests/metagpt/test_config.py b/tests/metagpt/test_config.pyindex d793b2615..eecabb546 100644--- a/tests/metagpt/test_config.py+++ b/tests/metagpt/test_config.py@@ -8,6 +8,7 @@from metagpt.config2 import Config, configfrom metagpt.configs.llm_config import LLMType+from tests.metagpt.provider.mock_llm_config import mock_llm_configdef 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"