Mercurial
diff love/poppy/apis/schemas.py @ 38:cf9caa4abc3e
[Love] FE and BE. Can chat and render images. Also created MCP for powerpoint generations.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 01 Dec 2025 20:35:56 -0800 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/love/poppy/apis/schemas.py Mon Dec 01 20:35:56 2025 -0800 @@ -0,0 +1,59 @@ +from uuid import UUID +from pydantic import BaseModel, ConfigDict, field_serializer +from datetime import datetime +from typing import Literal, Optional + + +class MessageBase(BaseModel): + role: Literal["user", "assistant"] + content: str + + model_config = ConfigDict(from_attributes=True) + + +class MessageCreate(MessageBase): + pass + + +class MessageOut(MessageBase): + id: UUID + image_url: Optional[str] = None + created_at: datetime + + @field_serializer("id") + def serialize_id(self, id: UUID): + return str(id) + + # Automatically populate image_url / image_urls from relationship + @classmethod + def from_orm_with_assets(cls, obj): + data = cls.model_validate(obj) + + image_assets = [ + a for a in getattr(obj, "assets", []) + if a.asset_type == "image" + ] + + image_urls = [a.url for a in image_assets if a.url] + data.image_url = image_urls[0] if image_urls else None + + return data + + +class ChatOut(BaseModel): + id: UUID + title: str + created_at: datetime + + model_config = ConfigDict(from_attributes=True) + + @field_serializer("id") + def serialize_id(self, id: UUID): + return str(id) + + +class ChatWithMessages(ChatOut): + messages: list[MessageOut] = [] + +class Chats(BaseModel): + chats: list[ChatOut] = []