mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-28 18:36:22 +02:00
refine code
This commit is contained in:
parent
b259203f74
commit
20b53fa859
1 changed files with 6 additions and 6 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue