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
+21 -4
View File
@@ -15,11 +15,13 @@ router = APIRouter(prefix="/sessions", tags=["sessions"])
class CreateSessionBody(BaseModel):
title: str | None = None
llmProviderId: int | None = None
llmModel: str | None = None
class PatchSessionBody(BaseModel):
title: str | None = Field(default=None, min_length=1, max_length=200)
llmProviderId: int | None = None
llmModel: str | None = None
@@ -28,6 +30,7 @@ def _session_vo(s) -> dict:
"threadId": s.thread_id,
"title": s.title,
"status": s.status.value,
"llmProviderId": s.llm_provider_id,
"llmModel": s.llm_model,
"createdAt": s.created_at.isoformat() + "Z",
"updatedAt": s.updated_at.isoformat() + "Z",
@@ -50,7 +53,12 @@ async def create_session(
actor: Actor = Depends(current_actor),
svc: SessionService = Depends(session_service),
):
s = await svc.create(actor, body.title, llm_model=body.llmModel)
s = await svc.create(
actor,
body.title,
llm_provider_id=body.llmProviderId,
llm_model=body.llmModel,
)
return ok(_session_vo(s))
@@ -61,14 +69,23 @@ async def patch_session(
actor: Actor = Depends(current_actor),
svc: SessionService = Depends(session_service),
):
if body.title is None and body.llmModel is None:
if body.title is None and body.llmModel is None and body.llmProviderId is None:
raise HTTPException(status_code=400, detail="无有效更新字段")
try:
s = None
if body.title is not None:
s = await svc.rename(actor, thread_id, body.title)
if body.llmModel is not None:
s = await svc.update_llm_model(actor, thread_id, body.llmModel)
if body.llmModel is not None or body.llmProviderId is not None:
if body.llmModel is None or body.llmProviderId is None:
raise HTTPException(
status_code=400, detail="切换模型须同时提供 llmProviderId 与 llmModel"
)
s = await svc.update_llm_selection(
actor,
thread_id,
llm_provider_id=body.llmProviderId,
llm_model=body.llmModel,
)
assert s is not None
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e)) from e