add test config

This commit is contained in:
geekan 2024-01-09 16:12:31 +08:00 committed by 莘权 马
parent 39fb4b0e6f
commit eeffb50a3e
2 changed files with 13 additions and 1 deletions

View file

@ -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