famfin-api / app /db /models_chat.py
AhmadYarAI's picture
Chat Messages send and receive and also load the history
9059e2e
raw
history blame contribute delete
720 Bytes
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.db.database import Base
class ChatMessage(Base):
__tablename__ = "chat_messages"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(
Integer,
ForeignKey("user_accounts.id", ondelete="CASCADE"),
nullable=False
)
# user OR assistant
role = Column(String(20), nullable=False)
content = Column(Text, nullable=False)
created_at = Column(
DateTime(timezone=True),
server_default=func.now()
)
# relationship
user = relationship("UserDB", back_populates="chats")