31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
"""QA 会话模型。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import BigInteger, Integer, TIMESTAMP, VARCHAR, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import Base
|
|
|
|
|
|
class QASession(Base):
|
|
__tablename__ = "qa_sessions"
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"tenant_id",
|
|
"external_conversation_key",
|
|
name="uq_qa_sessions_tenant_external_conversation_key",
|
|
),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True, index=True)
|
|
external_conversation_key: Mapped[Optional[str]] = mapped_column(VARCHAR(160), nullable=True, index=True)
|
|
title: Mapped[str] = mapped_column(VARCHAR(120), nullable=False, default="新会话")
|
|
project_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True, index=True)
|
|
started_at: Mapped[Optional[TIMESTAMP]] = mapped_column(TIMESTAMP, nullable=True, index=True)
|
|
last_message_at: Mapped[Optional[TIMESTAMP]] = mapped_column(TIMESTAMP, nullable=True, index=True)
|
|
message_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|