Add analysis feature
This commit is contained in:
@@ -8,6 +8,8 @@ from fastapi import APIRouter, Depends, HTTPException, Query, Response
|
||||
from loguru import logger
|
||||
from schemas import (
|
||||
ConversationArtifactOut,
|
||||
ConversationAnalysisFieldOut,
|
||||
ConversationAnalysisOut,
|
||||
ConversationDetailOut,
|
||||
ConversationListOut,
|
||||
ConversationMessageOut,
|
||||
@@ -40,6 +42,33 @@ def _session_out(row: ConversationSession) -> ConversationOut:
|
||||
)
|
||||
|
||||
|
||||
def _analysis_out(row: ConversationSession) -> ConversationAnalysisOut:
|
||||
data = row.analysis_data or {}
|
||||
plan = data.get("plan") if isinstance(data.get("plan"), dict) else {}
|
||||
definitions = plan.get("fields") if isinstance(plan.get("fields"), list) else []
|
||||
result = data.get("result") if isinstance(data.get("result"), dict) else {}
|
||||
fields = []
|
||||
for definition in definitions:
|
||||
if not isinstance(definition, dict):
|
||||
continue
|
||||
name = str(definition.get("name") or "")
|
||||
if not name:
|
||||
continue
|
||||
fields.append(
|
||||
ConversationAnalysisFieldOut(
|
||||
name=name,
|
||||
type=str(definition.get("type") or "string"),
|
||||
value=result.get(name),
|
||||
)
|
||||
)
|
||||
return ConversationAnalysisOut(
|
||||
status=row.analysis_status or "none",
|
||||
fields=fields,
|
||||
error=row.analysis_error or "",
|
||||
completed_at=data.get("completedAt"),
|
||||
)
|
||||
|
||||
|
||||
@router.get("", response_model=ConversationListOut)
|
||||
async def list_conversations(
|
||||
page: int = Query(1, ge=1),
|
||||
@@ -119,6 +148,7 @@ async def get_conversation(
|
||||
return ConversationDetailOut(
|
||||
**_session_out(conversation).model_dump(),
|
||||
extra=conversation.extra or {},
|
||||
analysis=_analysis_out(conversation),
|
||||
messages=[
|
||||
ConversationMessageOut(
|
||||
id=message.id,
|
||||
|
||||
Reference in New Issue
Block a user