Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 37:fb9bcd3145cb | 38:cf9caa4abc3e |
|---|---|
| 1 from uuid import UUID | |
| 2 from pydantic import BaseModel, ConfigDict, field_serializer | |
| 3 from datetime import datetime | |
| 4 from typing import Literal, Optional | |
| 5 | |
| 6 | |
| 7 class MessageBase(BaseModel): | |
| 8 role: Literal["user", "assistant"] | |
| 9 content: str | |
| 10 | |
| 11 model_config = ConfigDict(from_attributes=True) | |
| 12 | |
| 13 | |
| 14 class MessageCreate(MessageBase): | |
| 15 pass | |
| 16 | |
| 17 | |
| 18 class MessageOut(MessageBase): | |
| 19 id: UUID | |
| 20 image_url: Optional[str] = None | |
| 21 created_at: datetime | |
| 22 | |
| 23 @field_serializer("id") | |
| 24 def serialize_id(self, id: UUID): | |
| 25 return str(id) | |
| 26 | |
| 27 # Automatically populate image_url / image_urls from relationship | |
| 28 @classmethod | |
| 29 def from_orm_with_assets(cls, obj): | |
| 30 data = cls.model_validate(obj) | |
| 31 | |
| 32 image_assets = [ | |
| 33 a for a in getattr(obj, "assets", []) | |
| 34 if a.asset_type == "image" | |
| 35 ] | |
| 36 | |
| 37 image_urls = [a.url for a in image_assets if a.url] | |
| 38 data.image_url = image_urls[0] if image_urls else None | |
| 39 | |
| 40 return data | |
| 41 | |
| 42 | |
| 43 class ChatOut(BaseModel): | |
| 44 id: UUID | |
| 45 title: str | |
| 46 created_at: datetime | |
| 47 | |
| 48 model_config = ConfigDict(from_attributes=True) | |
| 49 | |
| 50 @field_serializer("id") | |
| 51 def serialize_id(self, id: UUID): | |
| 52 return str(id) | |
| 53 | |
| 54 | |
| 55 class ChatWithMessages(ChatOut): | |
| 56 messages: list[MessageOut] = [] | |
| 57 | |
| 58 class Chats(BaseModel): | |
| 59 chats: list[ChatOut] = [] |