Spaces:
Sleeping
Sleeping
Download src/models/message.py from sharjeel17/hackathon-2-phase-3: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/sharjeel17/hackathon-2-phase-3/resolve/main/src/models/message.py
- Command line
-
hf download hf://spaces/sharjeel17/hackathon-2-phase-3/src/models/message.py
-
curl -L -o message.py https://huggingface.co/spaces/sharjeel17/hackathon-2-phase-3/resolve/main/src/models/message.py
1.03 kB
| from sqlmodel import SQLModel, Field, Relationship | |
| from typing import Optional | |
| from datetime import datetime | |
| from sqlalchemy import JSON | |
| import uuid | |
| class Message(SQLModel, table=True): | |
| """ | |
| Represents an individual message in a conversation, either from user or AI | |
| """ | |
| __tablename__ = "messages" | |
| id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True) | |
| conversation_id: uuid.UUID = Field(foreign_key="conversations.id", index=True) # Links to parent conversation | |
| role: str = Field(regex="^(user|assistant)$") # Identifies the sender (user or assistant) | |
| content: str = Field(max_length=10000) # The actual message content (with reasonable limit) | |
| timestamp: datetime = Field(default_factory=datetime.utcnow) # When the message was created | |
| message_metadata: Optional[dict] = Field(default=None, sa_type=JSON) # Additional message metadata (tool calls, etc.) | |
| # Relationship to conversation | |
| conversation: "Conversation" = Relationship(back_populates="messages") |