mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 05:02:57 +00:00
将AI模块从module_application迁移到module_ai目录 新增聊天会话和消息的CRUD、服务和控制器 实现WebSocket聊天接口和前端组件 优化代码结构和性能,修复已知问题
26 lines
947 B
Python
26 lines
947 B
Python
from sqlalchemy import JSON, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.base_model import ModelMixin
|
|
|
|
|
|
class ChatMessageModel(ModelMixin):
|
|
"""
|
|
聊天消息表
|
|
"""
|
|
|
|
__tablename__: str = "ai_chat_message"
|
|
__table_args__: dict[str, str] = {"comment": "聊天消息表"}
|
|
|
|
session_id: Mapped[int] = mapped_column(
|
|
Integer,
|
|
ForeignKey("ai_chat_session.id", ondelete="CASCADE", onupdate="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
comment="会话ID"
|
|
)
|
|
type: Mapped[str] = mapped_column(String(20), nullable=False, comment="消息类型: user/assistant")
|
|
content: Mapped[str] = mapped_column(Text, nullable=False, comment="消息内容")
|
|
timestamp: Mapped[int] = mapped_column(Integer, nullable=False, comment="时间戳")
|
|
files: Mapped[dict | None] = mapped_column(JSON, nullable=True, comment="关联的文件信息")
|