Makhfi_AI / db /schemas /message.py
Aasher's picture
fix(chats): filter messages to include only relevant user and assistant content in chat retrieval
8909b6d
raw
history blame contribute delete
967 Bytes
import uuid
from datetime import datetime
from pydantic import BaseModel, Field, computed_field
from typing import Optional
# -------------------
# SCHEMAS FOR INPUT
# -------------------
class MessageCreate(BaseModel):
content: str = Field(..., description="The text content of the user's message.")
# -------------------
# SCHEMAS FOR OUTPUT
# -------------------
class MessageRead(BaseModel):
id: uuid.UUID
role: str
created_at: datetime
links: Optional[list[str]] = None
raw_content: Optional[str] = Field(None, alias='content', exclude=True)
answer: Optional[str] = Field(None, alias='answer', exclude=True)
# Step 2: The computed field now accesses the private, guaranteed-to-exist attributes
# on the MessageRead instance itself.
@computed_field
@property
def content(self) -> str:
return self.answer if self.answer is not None else self.raw_content
class Config:
from_attributes = True