feat: 模型管理独立页与会话级选模型

This commit is contained in:
2026-09-20 15:42:25 +08:00
parent ffb8d5f7dc
commit aac3424911
24 changed files with 845 additions and 523 deletions
+16 -6
View File
@@ -1,4 +1,4 @@
"""租户 LLM 运行时解析:Redis(Server 写入)→ Server 内部 API → 本地 fallback。"""
"""租户 LLM 运行时解析:Redis → Server 内部 API → 本地 fallback。"""
from __future__ import annotations
@@ -20,21 +20,28 @@ class LlmRuntimeService:
self._cache = cache
self._gateway = gateway
async def resolve_runtime(self, company_id: int) -> LlmRuntimeConfig:
cached = await self._cache.get(company_id)
async def resolve_runtime(
self, company_id: int, model: str | None = None
) -> LlmRuntimeConfig:
want = (model or "").strip() or None
cached = await self._cache.get(company_id, want)
if cached is not None and cached.api_key:
return cached
remote = await self._gateway.fetch(company_id)
remote = await self._gateway.fetch(company_id, want)
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
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
):
return LlmRuntimeConfig(
base_url=self._settings.llm_fallback_base_url.rstrip("/"),
@@ -45,5 +52,8 @@ class LlmRuntimeService:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="当前公司尚未配置模型 API,请先在智能助手设置中填写 OpenAI Compatible 凭证",
detail=(
"当前公司尚未配置模型 API,或所选模型未启用;"
"请在「模型管理」中配置凭证并启用模型"
),
)