41 lines
2.2 KiB
Python
41 lines
2.2 KiB
Python
from sqlalchemy import Float, Index, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class ApiModelPricing(Base, TimestampMixin):
|
|
"""API 模型价格表(全局统一配置)。
|
|
|
|
完全镜像 credit_ratios 表结构,将积分字段替换为金额字段(元)。
|
|
所有 API Key 共用一套价格表。
|
|
|
|
model_config_id 兼容 credit_ratios 字段名约定:
|
|
- gen_type=image 时,该字段保存 image_engines.id
|
|
- gen_type=video 时,该字段保存 video_engines.id
|
|
"""
|
|
|
|
__tablename__ = "api_model_pricings"
|
|
__table_args__ = (
|
|
Index("ix_api_model_pricings_gen_type_engine_resolution", "gen_type", "model_config_id", "resolution"),
|
|
Index("ix_api_model_pricings_gen_type_resolution", "gen_type", "resolution"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
model_config_id: Mapped[str] = mapped_column(String(32), index=True)
|
|
gen_type: Mapped[str] = mapped_column(String(16), default="video", index=True)
|
|
resolution: Mapped[str] = mapped_column(String(16), nullable=False, index=True)
|
|
|
|
# === 价格字段(元) ===
|
|
price_ratio: Mapped[float] = mapped_column(Float, nullable=False, default=1.0, comment="价格系数(乘数)")
|
|
base_price: Mapped[float] = mapped_column(Float, default=0.0, comment="基础价格(元)")
|
|
per_second_price: Mapped[float] = mapped_column(Float, default=0.0, comment="每秒价格(视频,元)")
|
|
|
|
# === 传入媒体附加费 ===
|
|
input_video_ratio: Mapped[float] = mapped_column(Float, default=1.0, comment="传入视频系数")
|
|
input_video_base_price: Mapped[float] = mapped_column(Float, default=0.0, comment="传入视频基础价(元)")
|
|
input_video_per_second_price: Mapped[float] = mapped_column(Float, default=0.0, comment="传入视频每秒价(元)")
|
|
input_image_ratio: Mapped[float] = mapped_column(Float, default=1.0, comment="传入图片系数")
|
|
input_image_base_price: Mapped[float] = mapped_column(Float, default=0.0, comment="传入图片基础价(元)")
|
|
input_image_per_image_price: Mapped[float] = mapped_column(Float, default=0.0, comment="传入图片每张价(元)")
|