Skip to content

Commit acebf60

Browse files
authored
Merge pull request #52 from pattern-tech/fix/routes
Fix/routes
2 parents 2976100 + 01f24d1 commit acebf60

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

api/src/conversation/routers/playground_conversation_router.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from uuid import UUID
22
from enum import Enum
3-
from pydantic import BaseModel
3+
from datetime import datetime
44
from sqlalchemy.orm import Session
5+
from pydantic import BaseModel, Field
56
from fastapi.responses import StreamingResponse
67
from typing import List, Optional, Dict, Literal
78
from fastapi import APIRouter, Depends, HTTPException, status
89

910
from src.db.sql_alchemy import Database
10-
from src.util.execptions import NotFoundError
1111
from src.auth.utils.get_token import authenticate_user
12+
from src.util.execptions import NotFoundError, RateLimitError
1213
from src.project.services.project_service import ProjectService
1314
from src.query_usage.services.query_usage_service import QueryUsageService
1415
from 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+
117122
class 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
)
324332
def 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))

api/src/project/routers/project_router.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from uuid import UUID
2+
from datetime import datetime
23
from typing import List, Dict
3-
from pydantic import BaseModel
44
from sqlalchemy.orm import Session
5+
from pydantic import BaseModel, Field
56
from fastapi import APIRouter, Depends, HTTPException, status
67

78
from src.db.sql_alchemy import Database
@@ -50,6 +51,9 @@ class ProjectOutput(BaseModel):
5051
id: UUID
5152
name: str
5253
workspace_id: UUID
54+
created_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
55+
updated_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
56+
deleted_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
5357

5458
class Config:
5559
from_attributes = True

api/src/query_usage/routers/query_usage_router.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from uuid import UUID
2-
from datetime import timedelta
2+
from datetime import datetime, timedelta
33
from sqlalchemy.orm import Session
44
from pydantic import BaseModel, Field
55
from typing import List, Optional, Dict
@@ -49,6 +49,9 @@ class QueryUsageOutput(BaseModel):
4949
"""
5050
id: UUID = Field(..., example="123e4567-e89b-12d3-a456-426614174000")
5151
provider: str = Field(..., example="morpheus")
52+
created_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
53+
updated_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
54+
deleted_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
5255

5356
class Config:
5457
from_attributes = True
@@ -106,7 +109,7 @@ def get_query_usage(
106109
description="Get number of used and total number of allowed query for a user",
107110
response_description="Number of used and total number of allowed query for a user",
108111
responses={
109-
403: {
112+
429: {
110113
"model": ExceptionResponse,
111114
"description": "Not enough balance"
112115
},
@@ -147,7 +150,7 @@ def get_user_query_usages(
147150
return global_response(data)
148151
except NotEnoughBalanceError as e:
149152
raise HTTPException(
150-
status_code=status.HTTP_403_FORBIDDEN, detail=str(e))
153+
status_code=status.HTTP_429_TOO_MANY_REQUESTS, detail=str(e))
151154
except Exception as e:
152155
raise HTTPException(
153156
status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))

api/src/user/routers/user_router.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from uuid import UUID
2-
from pydantic import BaseModel
2+
from datetime import datetime
3+
from pydantic import BaseModel, Field
34
from fastapi import APIRouter, Depends, HTTPException, status
45

56
from sqlalchemy.orm import Session
@@ -38,6 +39,9 @@ class UserOutput(BaseModel):
3839
email: str
3940
wallet_address: str
4041
chain_id: int
42+
created_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
43+
updated_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
44+
deleted_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
4145

4246
class Config:
4347
from_attributes = True

api/src/util/execptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,10 @@ class InvalidTokenError(Exception):
8585
def __init__(self, message="invalid token"):
8686
self.message = message
8787
super().__init__(f"{self.message}")
88+
89+
90+
class RateLimitError(Exception):
91+
"""Exception raised when the rate limit is exceeded"""
92+
def __init__(self, message="rate limit exceeded"):
93+
self.message = message
94+
super().__init__(self.message)

api/src/workspace/routers/workspace_router.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from uuid import UUID
2+
from datetime import datetime
23
from typing import List, Dict
34
from sqlalchemy.orm import Session
45
from pydantic import BaseModel, Field
@@ -48,6 +49,10 @@ class WorkspaceOutput(BaseModel):
4849
"""
4950
id: UUID = Field(..., example="123e4567-e89b-12d3-a456-426614174000")
5051
name: str = Field(..., example="New Workspace")
52+
created_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
53+
updated_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
54+
deleted_at: datetime = Field(None, example="2025-03-15T15:30:20+03:30")
55+
5156

5257
class Config:
5358
from_attributes = True

0 commit comments

Comments
 (0)