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
+13 -7
View File
@@ -14,21 +14,23 @@ logger = logging.getLogger(__name__)
class ServerLlmRuntimeGateway(LlmRuntimeGateway):
"""GET /api/internal/agent/llm-runtime?companyId=…(Agent Bearer)。"""
"""GET /api/internal/agent/llm-runtime?companyId=&model=(Agent Bearer)。"""
def __init__(self, settings: Settings) -> None:
self._settings = settings
async def fetch(self, company_id: int) -> LlmRuntimeConfig | None:
async def fetch(
self, company_id: int, model: str | None = None
) -> LlmRuntimeConfig | None:
url = f"{self._settings.server_base_url.rstrip('/')}/api/internal/agent/llm-runtime"
headers = {"Authorization": f"Bearer {self._settings.mcp_bearer_token}"}
params: dict[str, str | int] = {"companyId": company_id}
if model:
params["model"] = model
try:
async with httpx.AsyncClient(timeout=15.0) as client:
resp = await client.get(
url, params={"companyId": company_id}, headers=headers
)
resp = await client.get(url, params=params, headers=headers)
if resp.status_code == 400:
# 未配置
return None
resp.raise_for_status()
body = resp.json()
@@ -46,7 +48,11 @@ class ServerLlmRuntimeGateway(LlmRuntimeGateway):
context_window=_optional_positive_int(data.get("contextWindow")),
)
except Exception:
logger.exception("拉取 Server LLM runtime 失败 company_id=%s", company_id)
logger.exception(
"拉取 Server LLM runtime 失败 company_id=%s model=%s",
company_id,
model,
)
return None