1.0.0初始化源代码

This commit is contained in:
yuqianqian10204095yu
2026-03-23 15:40:36 +08:00
parent f13ecb3bba
commit cebc0a288f
53 changed files with 5300 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
"""
Token 使用记录模型
"""
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Float, Date
from sqlalchemy.sql import func
from .base import Base
class TokenUsage(Base):
"""Token 使用记录表"""
__tablename__ = "token_usages"
id = Column(Integer, primary_key=True, autoincrement=True, comment="记录 ID")
# 关联信息
virtual_user_id = Column(Integer, ForeignKey("virtual_users.id"), nullable=True, index=True, comment="虚拟用户 ID可为空系统级消耗")
interaction_id = Column(Integer, ForeignKey("interaction_records.id"), nullable=True, comment="互动记录 ID")
# Token 信息
tokens_used = Column(Integer, nullable=False, comment="使用的 Token 数量")
tokens_prompt = Column(Integer, default=0, comment="提示词 Token 数")
tokens_completion = Column(Integer, default=0, comment="完成响应 Token 数")
# AI 模型信息
ai_model = Column(String(100), nullable=False, comment="使用的 AI 模型")
action_type = Column(String(50), comment="操作类型generate_comment/generate_reply 等)")
# 日期分区(便于统计)
usage_date = Column(Date, server_default=func.now(), index=True, comment="使用日期")
# 时间戳
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
def __repr__(self):
return f"<TokenUsage(id={self.id}, tokens={self.tokens_used}, model='{self.ai_model}')>"