tyndale-ai-service/app/schemas.py

61 lines
1.9 KiB
Python

from typing import Literal
from pydantic import BaseModel, Field
class ChatRequest(BaseModel):
"""Request model for the /chat endpoint."""
message: str = Field(..., description="The user's message")
conversation_id: str | None = Field(
default=None, description="Optional conversation ID for continuity"
)
class ChatResponse(BaseModel):
"""Response model for the /chat endpoint."""
conversation_id: str = Field(..., description="Conversation ID (generated if not provided)")
response: str = Field(..., description="The LLM's response")
mode: Literal["local", "remote", "openai", "asksage"] = Field(..., description="Which adapter was used")
sources: list = Field(default_factory=list, description="Source references (empty for now)")
class HealthResponse(BaseModel):
"""Response model for the /health endpoint."""
status: str = Field(default="ok")
class ErrorResponse(BaseModel):
"""Standard error response model."""
detail: str = Field(..., description="Error description")
# --- SSE Streaming Event Models ---
class StreamChunkEvent(BaseModel):
"""SSE event for content chunks during streaming."""
type: Literal["chunk"] = "chunk"
content: str = Field(..., description="Content chunk from the LLM")
conversation_id: str = Field(..., description="Conversation ID")
class StreamDoneEvent(BaseModel):
"""SSE event signaling completion of streaming."""
type: Literal["done"] = "done"
conversation_id: str = Field(..., description="Conversation ID")
mode: Literal["local", "remote", "openai", "asksage"] = Field(..., description="Which adapter was used")
class StreamErrorEvent(BaseModel):
"""SSE event for errors during streaming."""
type: Literal["error"] = "error"
message: str = Field(..., description="Error message")
code: int = Field(default=500, description="HTTP status code")