feat: 公司支持多模型提供商与会话消歧选型

This commit is contained in:
2026-09-20 16:35:06 +08:00
parent d7e4a987c1
commit 9350323ff2
30 changed files with 1031 additions and 448 deletions
+22 -6
View File
@@ -23,22 +23,30 @@ class SessionService:
self,
actor: Actor,
title: str | None = None,
llm_provider_id: int | None = None,
llm_model: str | None = None,
) -> Session:
now = datetime.utcnow()
model = (llm_model or "").strip() or None
if not model and self._llm_runtime is not None:
provider_id = llm_provider_id
if (not model or provider_id is None) and self._llm_runtime is not None:
try:
rt = await self._llm_runtime.resolve_runtime(actor.company_id)
model = rt.model or None
rt = await self._llm_runtime.resolve_runtime(
actor.company_id,
provider_id=provider_id,
model=model,
)
model = rt.model or model
provider_id = rt.provider_id if rt.provider_id is not None else provider_id
except Exception:
model = None
pass
session = Session(
thread_id=str(uuid.uuid4()),
company_id=actor.company_id,
user_id=actor.user_id,
title=(title or "新对话").strip() or "新对话",
status=SessionStatus.ACTIVE,
llm_provider_id=provider_id,
llm_model=model,
created_at=now,
updated_at=now,
@@ -59,13 +67,21 @@ class SessionService:
session.title = title.strip() or session.title
return await self._sessions.update(session)
async def update_llm_model(
self, actor: Actor, thread_id: str, llm_model: str
async def update_llm_selection(
self,
actor: Actor,
thread_id: str,
*,
llm_provider_id: int,
llm_model: str,
) -> Session:
model = (llm_model or "").strip()
if not model:
raise ValueError("模型不能为空")
if llm_provider_id is None or int(llm_provider_id) <= 0:
raise ValueError("提供商不能为空")
session = await self.require_owned(actor, thread_id)
session.llm_provider_id = int(llm_provider_id)
session.llm_model = model
return await self._sessions.update(session)