Files
wecom_it_smart_desk/backend/app/models/conversation_annotation.py

101 lines
2.8 KiB
Python
Raw Permalink 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.
# =============================================================================
# 企微IT智能服务台 — 会话标注模型
# =============================================================================
# 说明:对应数据库 conversation_annotations 表
# 存储坐席对AI回复的标注数据,用于模型优化
# =============================================================================
import uuid
from datetime import datetime
from sqlalchemy import DateTime, Index, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class ConversationAnnotation(Base):
"""会话标注模型 — 对应 conversation_annotations 表。
存储坐席对AI回复的标注数据,用于持续优化AI能力。
Attributes:
id: 标注IDUUID
conversation_id: 会话ID
agent_id: 坐席ID
message_id: 被标注的消息IDAI回复)
feedback: 反馈类型(useful=有用/useless=无用)
comment: 备注(可选)
created_at: 创建时间
"""
# 表名
__tablename__ = "conversation_annotations"
# --------------------------------------------------------------------------
# 字段定义
# --------------------------------------------------------------------------
# 主键
id: Mapped[str] = mapped_column(
String(36),
primary_key=True,
default=lambda: str(uuid.uuid4()),
)
# 会话ID
conversation_id: Mapped[str] = mapped_column(
String(36),
nullable=False,
index=True,
comment="会话ID",
)
# 坐席ID
agent_id: Mapped[str] = mapped_column(
String(36),
nullable=False,
comment="坐席ID",
)
# 被标注的消息ID
message_id: Mapped[str] = mapped_column(
String(36),
nullable=False,
comment="被标注的消息ID",
)
# 反馈类型
feedback: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment="useful=有用/useless=无用",
)
# 备注
comment: Mapped[str] = mapped_column(
Text,
nullable=True,
comment="备注",
)
# 创建时间
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
default=datetime.now,
comment="创建时间",
)
# --------------------------------------------------------------------------
# 索引定义
# --------------------------------------------------------------------------
__table_args__ = (
Index("idx_annotation_conversation", "conversation_id"),
Index("idx_annotation_message", "message_id"),
)
def __repr__(self) -> str:
"""标注对象的字符串表示。"""
return f"<ConversationAnnotation(id={self.id}, feedback={self.feedback})>"