mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:09:19 +08:00
feat: 公司支持多模型提供商与会话消歧选型
This commit is contained in:
@@ -21,32 +21,37 @@ class LlmRuntimeService:
|
||||
self._gateway = gateway
|
||||
|
||||
async def resolve_runtime(
|
||||
self, company_id: int, model: str | None = None
|
||||
self,
|
||||
company_id: int,
|
||||
provider_id: int | None = None,
|
||||
model: str | None = None,
|
||||
) -> LlmRuntimeConfig:
|
||||
want = (model or "").strip() or None
|
||||
cached = await self._cache.get(company_id, want)
|
||||
want_model = (model or "").strip() or None
|
||||
want_provider = provider_id
|
||||
cached = await self._cache.get(company_id, want_provider, want_model)
|
||||
if cached is not None and cached.api_key:
|
||||
return cached
|
||||
|
||||
remote = await self._gateway.fetch(company_id, want)
|
||||
remote = await self._gateway.fetch(company_id, want_provider, want_model)
|
||||
if remote is not None and remote.api_key and remote.base_url and remote.model:
|
||||
await self._cache.set(
|
||||
company_id,
|
||||
remote,
|
||||
self._settings.llm_cache_ttl_seconds,
|
||||
model=remote.model,
|
||||
)
|
||||
return remote
|
||||
|
||||
if (
|
||||
self._settings.llm_fallback_enabled
|
||||
and self._settings.llm_fallback_api_key
|
||||
and not want
|
||||
and not want_model
|
||||
and want_provider is None
|
||||
):
|
||||
return LlmRuntimeConfig(
|
||||
base_url=self._settings.llm_fallback_base_url.rstrip("/"),
|
||||
api_key=self._settings.llm_fallback_api_key,
|
||||
model=self._settings.llm_fallback_model,
|
||||
provider_id=None,
|
||||
context_window=None,
|
||||
)
|
||||
|
||||
@@ -54,6 +59,6 @@ class LlmRuntimeService:
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=(
|
||||
"当前公司尚未配置模型 API,或所选模型未启用;"
|
||||
"请在「模型管理」中配置凭证并启用模型"
|
||||
"请在「模型管理」中配置提供商并启用模型"
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user