diff --git a/metagpt/context.py b/metagpt/context.py index 495fe9e2f..ba859ed5c 100644 --- a/metagpt/context.py +++ b/metagpt/context.py @@ -45,24 +45,24 @@ class AttrDict(BaseModel): class LLMMixin: """Mixin class for LLM""" - config: Optional[Config] = None - llm_config: Optional[LLMConfig] = None + # _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) + self._llm_config = self._config.get_llm_config(name, provider) # 重置LLM实例 self._llm_instance = None @property def llm(self) -> BaseLLM: """Return the LLM instance""" - if not self.llm_config: + 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) + if not self._llm_instance and self._llm_config: + self._llm_instance = create_llm_instance(self._llm_config) return self._llm_instance