55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
"""
|
|
Token 使用相关 Schema
|
|
"""
|
|
from pydantic import BaseModel, Field
|
|
from typing import Optional, List
|
|
from datetime import date, datetime
|
|
|
|
|
|
class TokenUsageBase(BaseModel):
|
|
"""Token 使用基础 Schema"""
|
|
tokens_used: int = Field(..., description="使用的 Token 数量")
|
|
ai_model: str = Field(..., description="使用的 AI 模型")
|
|
action_type: Optional[str] = Field(None, description="操作类型")
|
|
|
|
|
|
class TokenUsageResponse(TokenUsageBase):
|
|
"""Token 使用响应"""
|
|
id: int
|
|
virtual_user_id: Optional[int]
|
|
interaction_id: Optional[int]
|
|
tokens_prompt: int
|
|
tokens_completion: int
|
|
usage_date: date
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class TokenUsageStats(BaseModel):
|
|
"""Token 使用统计"""
|
|
today_tokens: int = Field(0, description="今日 Token 数")
|
|
yesterday_tokens: int = Field(0, description="昨日 Token 数")
|
|
month_tokens: int = Field(0, description="当月 Token 数")
|
|
remaining_tokens: int = Field(0, description="剩余 Token 数")
|
|
total_limit: int = Field(0, description="总限额")
|
|
|
|
|
|
class DailyTokenUsage(BaseModel):
|
|
"""每日 Token 使用"""
|
|
date: str
|
|
tokens: int
|
|
|
|
|
|
class MonthlyTokenUsage(BaseModel):
|
|
"""每月 Token 使用"""
|
|
month: str
|
|
tokens: int
|
|
|
|
|
|
class TokenUsageChartResponse(BaseModel):
|
|
"""Token 使用图表响应"""
|
|
daily_usages: List[DailyTokenUsage]
|
|
monthly_usages: List[MonthlyTokenUsage]
|