This commit is contained in:
Timothy Jaeryang Baek 2025-12-26 14:05:16 +04:00
parent df106099a1
commit 9c61e95ecb

View file

@ -197,13 +197,19 @@ def get_session_user_chat_usage_stats(
) )
############################ ############################
# GetChatStatsExport # GetChatStatsExport
############################ ############################
@router.get("/stats/export", response_model=list[ChatStatsExport]) class ChatStatsExportList(BaseModel):
type: str = "chats"
items: list[ChatStatsExport]
total: int
page: int
@router.get("/stats/export", response_model=ChatStatsExportList)
async def export_chat_stats( async def export_chat_stats(
request: Request, request: Request,
chat_id: Optional[str] = None, chat_id: Optional[str] = None,
@ -264,7 +270,9 @@ async def export_chat_stats(
if isinstance(content, str): if isinstance(content, str):
content_length = len(content) content_length = len(content)
else: else:
content_length = 0 # Handle cases where content might be None or not string content_length = (
0 # Handle cases where content might be None or not string
)
# Extract rating safely # Extract rating safely
rating = message.get("annotation", {}).get("rating") rating = message.get("annotation", {}).get("rating")
@ -372,7 +380,9 @@ async def export_chat_stats(
) )
) )
return chat_stats_export_list return ChatStatsExportList(
items=chat_stats_export_list, total=result.total, page=page
)
except Exception as e: except Exception as e:
log.exception(e) log.exception(e)
@ -381,7 +391,6 @@ async def export_chat_stats(
) )
@router.delete("/", response_model=bool) @router.delete("/", response_model=bool)
async def delete_all_user_chats(request: Request, user=Depends(get_verified_user)): async def delete_all_user_chats(request: Request, user=Depends(get_verified_user)):