Spaces:
Running
Running
File size: 1,185 Bytes
521f25e | 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 | """
DATA MODELS MODULE
=================
This file defines the pydantic models used for API request, response, and
internal chat storage. FastAPI uses these o validate incoming JSON and to
serialize responses; the chat service uses them when saving/loading sessions.
MODELS:
ChatRequest - Body of POST /chat and POST /chat/realtime (message + optional session_id).
ChatResponse - returned by both chat endpoints (response text + session_id).
ChatMessage - One message in a conversation (role + content). Used inside ChatHistory.
ChatHistory - Full conversation: session_id + list of ChatMessage. Used when saving to disk
"""
from pydantic import BaseModel, Field
from typing import List, Optional
class ChatMessage(BaseModel):
role: str
content: str
class ChatRequest(BaseModel):
message: str = Field(..., min_length=1, max_length=22_000)
session_id: Optional[str] = None
tts: bool = False
class ChatResponse(BaseModel):
response: str
session_id: str
class ChatHistory(BaseModel):
session_id: str
messages: List[ChatMessage]
class TTSRequest(BaseModel):
text: str = Field(..., min_length=1, max_length=5000)
|