Spaces:
Sleeping
Sleeping
Download src/models/message.py from ibad363/todo-backend: direct link, hf CLI and curl.
- Browser
- Download file 880 Bytes
-
https://huggingface.co/spaces/ibad363/todo-backend/resolve/main/src/models/message.py
- Command line
-
hf download hf://spaces/ibad363/todo-backend/src/models/message.py
-
curl -L -o message.py https://huggingface.co/spaces/ibad363/todo-backend/resolve/main/src/models/message.py
880 Bytes
| from datetime import datetime | |
| from typing import Optional, TYPE_CHECKING | |
| from sqlmodel import SQLModel, Field, Relationship | |
| if TYPE_CHECKING: | |
| from .conversation import Conversation | |
| class Message(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| conversation_id: int = Field(foreign_key="conversation.id", index=True) | |
| user_id: int = Field(foreign_key="user.id", index=True) | |
| role: str = Field(index=True) # "user" or "assistant" | |
| content: str = Field(max_length=4000) | |
| created_at: datetime = Field(default_factory=datetime.utcnow, index=True) | |
| conversation: "Conversation" = Relationship(back_populates="messages") | |
| class MessageCreate(SQLModel): | |
| role: str | |
| content: str | |
| class MessageRead(SQLModel): | |
| id: int | |
| conversation_id: int | |
| user_id: int | |
| role: str | |
| content: str | |
| created_at: datetime | |