File size: 1,635 Bytes
ac0f906 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
from pydantic import BaseModel, Field, ConfigDict
from typing import Optional, List, Dict, Any
from datetime import datetime
import uuid
class SessionBase(BaseModel):
"""Base model for session data"""
session_id: str = Field(default_factory=lambda: str(uuid.uuid4()))
factor: str
action: str
first_name: str
last_name: Optional[str] = None
message: Optional[str] = None
user_id: str
username: Optional[str] = None
class SessionCreate(SessionBase):
"""Model for creating new session"""
response: Optional[str] = None
class SessionResponse(SessionBase):
"""Response model for session data"""
created_at: str
response: Optional[str] = None
model_config = ConfigDict(
json_schema_extra={
"example": {
"session_id": "123e4567-e89b-12d3-a456-426614174000",
"factor": "user",
"action": "asking_freely",
"created_at": "2023-06-01 14:30:45",
"first_name": "John",
"last_name": "Doe",
"message": "How can I find emergency contacts?",
"user_id": "12345678",
"username": "johndoe",
"response": "You can find emergency contacts in the Emergency section..."
}
}
)
class HistoryRequest(BaseModel):
"""Request model for history"""
user_id: str
n: int = 3
class QuestionAnswer(BaseModel):
"""Model for question-answer pair"""
question: str
answer: str
class HistoryResponse(BaseModel):
"""Response model for history"""
history: List[QuestionAnswer] |