mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 01:09:19 +08:00
feat: 模型管理独立页与会话级选模型
This commit is contained in:
@@ -15,10 +15,12 @@ router = APIRouter(prefix="/sessions", tags=["sessions"])
|
||||
|
||||
class CreateSessionBody(BaseModel):
|
||||
title: str | None = None
|
||||
llmModel: str | None = None
|
||||
|
||||
|
||||
class RenameBody(BaseModel):
|
||||
title: str = Field(min_length=1, max_length=200)
|
||||
class PatchSessionBody(BaseModel):
|
||||
title: str | None = Field(default=None, min_length=1, max_length=200)
|
||||
llmModel: str | None = None
|
||||
|
||||
|
||||
def _session_vo(s) -> dict:
|
||||
@@ -26,6 +28,7 @@ def _session_vo(s) -> dict:
|
||||
"threadId": s.thread_id,
|
||||
"title": s.title,
|
||||
"status": s.status.value,
|
||||
"llmModel": s.llm_model,
|
||||
"createdAt": s.created_at.isoformat() + "Z",
|
||||
"updatedAt": s.updated_at.isoformat() + "Z",
|
||||
"lastMessageAt": s.last_message_at.isoformat() + "Z" if s.last_message_at else None,
|
||||
@@ -47,19 +50,28 @@ async def create_session(
|
||||
actor: Actor = Depends(current_actor),
|
||||
svc: SessionService = Depends(session_service),
|
||||
):
|
||||
s = await svc.create(actor, body.title)
|
||||
s = await svc.create(actor, body.title, llm_model=body.llmModel)
|
||||
return ok(_session_vo(s))
|
||||
|
||||
|
||||
@router.patch("/{thread_id}")
|
||||
async def rename_session(
|
||||
async def patch_session(
|
||||
thread_id: str,
|
||||
body: RenameBody,
|
||||
body: PatchSessionBody,
|
||||
actor: Actor = Depends(current_actor),
|
||||
svc: SessionService = Depends(session_service),
|
||||
):
|
||||
if body.title is None and body.llmModel is None:
|
||||
raise HTTPException(status_code=400, detail="无有效更新字段")
|
||||
try:
|
||||
s = await svc.rename(actor, thread_id, body.title)
|
||||
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)
|
||||
assert s is not None
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
except LookupError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e)) from e
|
||||
return ok(_session_vo(s))
|
||||
|
||||
Reference in New Issue
Block a user