Pretor/pretor/adapter/model_adapter/provider_manager.py

41 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def create_agent(self, agent_name: str,
system_prompt: str,
provider_title: str,
model_id: str,
output_type: ResponseModel,
deps_type: DepsModel) -> Agent:
"""
create_agent方法将保存的适配器转化为agent对象并返回
Args:
agent_name: agent名字代表实例化个体起的名字
system_prompt: 系统提示词给llm的系统提示词
provider_title: 供应商名称
model_id: 模型Id实例化agent所输入的model_id
output_type: 输出格式实例化agent后对应llm所应当输出的格式
deps_type: 依赖格式输入llm的格式
Returns:
一个pydanticAI的Agent对象包含对应的apikey,url,model_id等信息应当挂载到individual类的agent属性下
Raises:
ProviderNotExistError 当在provider_register属性里找不到供应商的自定义名称时抛出
ModelNotExistError 在获取的provider的模型列表中找不到输入的model_id抛出
"""
if provider_title not in self.provider_register:
raise ProviderNotExistError("提供商不存在")
provider = self.provider_register[provider_title]
if model_id not in provider.provider_models:
raise ModelNotExistError("模型不存在")
model = self._agent_factory.create_model(provider.provider_type,
provider.provider_apikey,
provider.provider_url,
model_id)
agent = Agent(model=model,
name=agent_name,
system_prompt=system_prompt,
output_type=output_type,
deps_type=deps_type)
return agent