baodan/api/insurance/models/chat_session.py

27 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""会话模型。"""
from sqlalchemy import Column, Integer, String, TIMESTAMP, func, Boolean
from insurance.db.compat import db
class ChatSession(db.Model):
"""会话表。"""
__tablename__ = "insurance_chat_sessions"
id = Column(Integer, primary_key=True, autoincrement=True)
session_id = Column(String(128), unique=True, nullable=False, comment="本地会话 ID")
user_id = Column(String(64), nullable=False, comment="用户 ID")
name = Column(String(256), default="新会话", comment="会话名称")
baodan_conversation_id = Column(String(128), nullable=True, comment="BaoDan 返回的 conversation_id用于保持上下文")
is_deleted = Column(Boolean, default=False, comment="是否已删除")
created_at = Column(TIMESTAMP, server_default=func.now())
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
def to_dict(self):
return {
"id": self.session_id,
"name": self.name,
"baodan_conversation_id": self.baodan_conversation_id,
"created_at": str(self.created_at) if self.created_at else None,
"updated_at": str(self.updated_at) if self.updated_at else None,
}