前台页面/conversation修改积分计算逻辑
1、后台页面/credit-ratios,需要选择视频,上边是模型价格,下边增加传入视频价格,也要输入对应的倍率、基础积分、每秒积分 2、前台/conversation获取积分逻辑的接口也要增加对应的传入视频的比例 3、然后前台根据用户上传视频自动获取对应的比例加上对应模型选择的积分计算总积分 4、后台提交也要验证对应的积分是否正确 5、多个视频总时长需限制15s,最低视频时长2s
This commit is contained in:
@@ -65,6 +65,7 @@ async def calc_video_credits(
|
||||
duration: int,
|
||||
resolution: str,
|
||||
engine_id: str | None = None,
|
||||
input_video_duration: float | None = None,
|
||||
) -> float:
|
||||
"""Calculate video credits using CreditRatio table, with fallback to hardcoded.
|
||||
|
||||
@@ -72,8 +73,9 @@ async def calc_video_credits(
|
||||
1. gen_type=video + engine_id + resolution 精确规则;
|
||||
2. gen_type=video + resolution 下 base_credits/per_second_credits 最高规则;
|
||||
3. 原硬编码默认算法。
|
||||
|
||||
input_video_duration: 用户上传的参考视频总时长(秒),不为空时额外计费
|
||||
"""
|
||||
# 如果engine_id为空,默认查询权重最高的视频引擎积分规则
|
||||
if not engine_id:
|
||||
video_engines_result = await db.execute(
|
||||
select(VideoEngine.id)
|
||||
@@ -89,13 +91,21 @@ async def calc_video_credits(
|
||||
engine_id=engine_id,
|
||||
)
|
||||
if ratio:
|
||||
return round((ratio.base_credits + ratio.per_second_credits * duration) * ratio.ratio, 2)
|
||||
base_cost = (ratio.base_credits + ratio.per_second_credits * duration) * ratio.ratio
|
||||
if input_video_duration and input_video_duration > 0:
|
||||
input_video_cost = (
|
||||
ratio.input_video_base_credits + ratio.input_video_per_second_credits * input_video_duration
|
||||
) * ratio.input_video_ratio
|
||||
base_cost += input_video_cost
|
||||
return round(base_cost, 2)
|
||||
|
||||
# Fallback
|
||||
base = 60.0
|
||||
duration_cost = duration * 2.0
|
||||
multiplier = {"480p": 1, "1080p": 2, "720p": 1.5}.get(resolution, 1.0)
|
||||
return round((base + duration_cost) * multiplier, 2)
|
||||
total = (base + duration_cost) * multiplier
|
||||
if input_video_duration and input_video_duration > 0:
|
||||
total += input_video_duration * 0.5 * multiplier
|
||||
return round(total, 2)
|
||||
|
||||
|
||||
def calc_credits(duration: int, resolution: str) -> float:
|
||||
|
||||
Reference in New Issue
Block a user