69 lines
2.7 KiB
Python
69 lines
2.7 KiB
Python
"""
|
||
互动记录模型
|
||
"""
|
||
from sqlalchemy import Column, Integer, String, DateTime, Enum, Text, ForeignKey, Boolean, Float
|
||
from sqlalchemy.sql import func
|
||
from sqlalchemy.orm import relationship
|
||
import enum
|
||
|
||
from .base import Base
|
||
|
||
|
||
class InteractionType(str, enum.Enum):
|
||
"""互动类型枚举"""
|
||
COMMENT = "comment" # 评论
|
||
REPLY = "reply" # 回复
|
||
LIKE = "like" # 点赞
|
||
FAVORITE = "favorite" # 收藏
|
||
SHARE = "share" # 转发
|
||
|
||
|
||
class InteractionStatus(str, enum.Enum):
|
||
"""互动状态枚举"""
|
||
PENDING = "pending" # 待执行
|
||
SUCCESS = "success" # 成功
|
||
FAILED = "failed" # 失败
|
||
RETRYING = "retrying" # 重试中
|
||
|
||
|
||
class InteractionRecord(Base):
|
||
"""互动记录表"""
|
||
__tablename__ = "interaction_records"
|
||
|
||
id = Column(Integer, primary_key=True, autoincrement=True, comment="记录 ID")
|
||
|
||
# 关联信息
|
||
virtual_user_id = Column(Integer, ForeignKey("virtual_users.id"), nullable=False, index=True, comment="虚拟用户 ID")
|
||
virtual_user = relationship("VirtualUser", backref="interaction_records")
|
||
|
||
news_id = Column(String(100), nullable=False, index=True, comment="新闻 ID")
|
||
news_title = Column(String(500), comment="新闻标题")
|
||
|
||
# 互动内容
|
||
interaction_type = Column(Enum(InteractionType), nullable=False, comment="互动类型")
|
||
content = Column(Text, comment="互动内容(评论/回复的文本)")
|
||
target_comment_id = Column(String(100), comment="目标评论 ID(回复时使用)")
|
||
|
||
# 执行状态
|
||
status = Column(Enum(InteractionStatus), default=InteractionStatus.PENDING, comment="执行状态")
|
||
retry_count = Column(Integer, default=0, comment="重试次数")
|
||
error_message = Column(Text, comment="错误信息(失败时)")
|
||
|
||
# AI 相关信息
|
||
ai_model_used = Column(String(100), comment="使用的 AI 模型")
|
||
tokens_used = Column(Integer, default=0, comment="消耗的 Token 数")
|
||
prompt_content = Column(Text, comment="发送给 AI 的提示词")
|
||
ai_response = Column(Text, comment="AI 返回的内容")
|
||
|
||
# 接口响应
|
||
api_response = Column(Text, comment="会会接口返回的原始响应")
|
||
api_request_id = Column(String(200), comment="接口请求 ID")
|
||
|
||
# 时间戳
|
||
execution_time = Column(DateTime, server_default=func.now(), comment="执行时间")
|
||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
||
|
||
def __repr__(self):
|
||
return f"<InteractionRecord(id={self.id}, user_id={self.virtual_user_id}, type='{self.interaction_type}', status='{self.status}')>"
|