File size: 5,520 Bytes
22a3c56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
"""Data models"""
from datetime import datetime
from typing import Optional, List, Union
from pydantic import BaseModel
class Token(BaseModel):
"""Token model"""
id: Optional[int] = None
token: str
email: str
name: Optional[str] = ""
st: Optional[str] = None
rt: Optional[str] = None
remark: Optional[str] = None
expiry_time: Optional[datetime] = None
is_active: bool = True
cooled_until: Optional[datetime] = None
created_at: Optional[datetime] = None
last_used_at: Optional[datetime] = None
use_count: int = 0
# 订阅信息
plan_type: Optional[str] = None # 账户类型,如 chatgpt_team
plan_title: Optional[str] = None # 套餐名称,如 ChatGPT Business
subscription_end: Optional[datetime] = None # 套餐到期时间
# Sora2 支持信息
sora2_supported: Optional[bool] = None # 是否支持Sora2
sora2_invite_code: Optional[str] = None # Sora2邀请码
sora2_redeemed_count: int = 0 # Sora2已用次数
sora2_total_count: int = 0 # Sora2总次数
# Sora2 剩余次数
sora2_remaining_count: int = 0 # Sora2剩余可用次数
sora2_cooldown_until: Optional[datetime] = None # Sora2冷却时间
# 功能开关
image_enabled: bool = True # 是否启用图片生成
video_enabled: bool = True # 是否启用视频生成
class TokenStats(BaseModel):
"""Token statistics"""
id: Optional[int] = None
token_id: int
image_count: int = 0
video_count: int = 0
error_count: int = 0
last_error_at: Optional[datetime] = None
class Task(BaseModel):
"""Task model"""
id: Optional[int] = None
task_id: str
token_id: int
model: str
prompt: str
status: str = "processing" # processing/completed/failed
progress: float = 0.0
result_urls: Optional[str] = None # JSON array
error_message: Optional[str] = None
created_at: Optional[datetime] = None
completed_at: Optional[datetime] = None
class RequestLog(BaseModel):
"""Request log model"""
id: Optional[int] = None
token_id: Optional[int] = None
operation: str
request_body: Optional[str] = None
response_body: Optional[str] = None
status_code: int
duration: float
created_at: Optional[datetime] = None
class AdminConfig(BaseModel):
"""Admin configuration"""
id: int = 1
admin_username: str # Read from database, initialized from setting.toml on first startup
admin_password: str # Read from database, initialized from setting.toml on first startup
error_ban_threshold: int = 3
updated_at: Optional[datetime] = None
class ProxyConfig(BaseModel):
"""Proxy configuration"""
id: int = 1
proxy_enabled: bool # Read from database, initialized from setting.toml on first startup
proxy_url: Optional[str] = None # Read from database, initialized from setting.toml on first startup
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
class WatermarkFreeConfig(BaseModel):
"""Watermark-free mode configuration"""
id: int = 1
watermark_free_enabled: bool # Read from database, initialized from setting.toml on first startup
parse_method: str # Read from database, initialized from setting.toml on first startup
custom_parse_url: Optional[str] = None # Read from database, initialized from setting.toml on first startup
custom_parse_token: Optional[str] = None # Read from database, initialized from setting.toml on first startup
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
class CacheConfig(BaseModel):
"""Cache configuration"""
id: int = 1
cache_enabled: bool # Read from database, initialized from setting.toml on first startup
cache_timeout: int # Read from database, initialized from setting.toml on first startup
cache_base_url: Optional[str] = None # Read from database, initialized from setting.toml on first startup
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
class GenerationConfig(BaseModel):
"""Generation timeout configuration"""
id: int = 1
image_timeout: int # Read from database, initialized from setting.toml on first startup
video_timeout: int # Read from database, initialized from setting.toml on first startup
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
class TokenRefreshConfig(BaseModel):
"""Token refresh configuration"""
id: int = 1
at_auto_refresh_enabled: bool # Read from database, initialized from setting.toml on first startup
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
# API Request/Response models
class ChatMessage(BaseModel):
role: str
content: Union[str, List[dict]] # Support both string and array format (OpenAI multimodal)
class ChatCompletionRequest(BaseModel):
model: str
messages: List[ChatMessage]
image: Optional[str] = None
video: Optional[str] = None # Base64 encoded video file
remix_target_id: Optional[str] = None # Sora share link video ID for remix
stream: bool = False
max_tokens: Optional[int] = None
class ChatCompletionChoice(BaseModel):
index: int
message: Optional[dict] = None
delta: Optional[dict] = None
finish_reason: Optional[str] = None
class ChatCompletionResponse(BaseModel):
id: str
object: str = "chat.completion"
created: int
model: str
choices: List[ChatCompletionChoice]
|