11from uuid import UUID
22from enum import Enum
3- from pydantic import BaseModel
3+ from datetime import datetime
44from sqlalchemy .orm import Session
5+ from pydantic import BaseModel , Field
56from fastapi .responses import StreamingResponse
67from typing import List , Optional , Dict , Literal
78from fastapi import APIRouter , Depends , HTTPException , status
89
910from src .db .sql_alchemy import Database
10- from src .util .execptions import NotFoundError
1111from src .auth .utils .get_token import authenticate_user
12+ from src .util .execptions import NotFoundError , RateLimitError
1213from src .project .services .project_service import ProjectService
1314from src .query_usage .services .query_usage_service import QueryUsageService
1415from src .conversation .services .conversation_service import ConversationService
@@ -57,6 +58,9 @@ class CreateConversationInput(BaseModel):
5758 name : str
5859 project_id : UUID
5960 conversation_id : Optional [UUID ] = None
61+ created_at : datetime = Field (None , example = "2025-03-15T15:30:20+03:30" )
62+ updated_at : datetime = Field (None , example = "2025-03-15T15:30:20+03:30" )
63+ deleted_at : datetime = Field (None , example = "2025-03-15T15:30:20+03:30" )
6064
6165 class Config :
6266 from_attributes = True
@@ -114,12 +118,14 @@ class ChatHistory(BaseModel):
114118 """
115119 history : List [HistoryMessage ]
116120
121+
117122class TitleOutput (BaseModel ):
118123 """
119124 Schema for title output.
120125 """
121126 title : str
122127
128+
123129@router .post (
124130 "" ,
125131 response_model = GlobalResponse [ConversationOutput , Dict ],
@@ -200,6 +206,8 @@ def get_conversation(
200206 - **service**: Conversation service handling business logic.
201207 - **user_id**: The authenticated user's ID.
202208
209+ - **metadata**: The chat history metadata.
210+
203211 Returns:
204212 ConversationOutput: The conversation data with chat history metadata.
205213 """
@@ -318,7 +326,7 @@ def update_conversation(
318326 400 : {
319327 "model" : ExceptionResponse ,
320328 "description" : "Bad request received"
321- }
329+ }
322330 },
323331)
324332def delete_conversation (
@@ -364,6 +372,10 @@ def delete_conversation(
364372 400 : {
365373 "model" : ExceptionResponse ,
366374 "description" : "Bad request received"
375+ },
376+ 429 : {
377+ "model" : ExceptionResponse ,
378+ "description" : "Rate daily limit exceeded"
367379 }
368380 }
369381)
@@ -387,8 +399,6 @@ async def send_message(
387399 - **service**: Conversation service handling business logic.
388400 - **user_id**: The authenticated user's ID.
389401
390- - **metadata**: The chat history metadata.
391-
392402 Returns:
393403 StreamingResponse: If `stream` is true.
394404 dict: A JSON response containing the complete message data if `stream` is false.
@@ -436,6 +446,9 @@ async def send_message(
436446 raise HTTPException (
437447 status_code = status .HTTP_404_NOT_FOUND , detail = str (e )
438448 )
449+ except RateLimitError as e :
450+ raise HTTPException (
451+ status_code = status .HTTP_429_TOO_MANY_REQUESTS , detail = str (e ))
439452 except Exception as e :
440453 raise HTTPException (
441454 status_code = status .HTTP_400_BAD_REQUEST , detail = str (e ))
0 commit comments