视频复刻积分规则优化
This commit is contained in:
@@ -646,6 +646,14 @@ def start_pending_free_video(task: AITask) -> AITask:
|
||||
team=task.team,
|
||||
)
|
||||
reserve_amount = video_reserve_amount(quote.points, rule=quote.meta.get("rule"))
|
||||
try:
|
||||
digest_points = Decimal(str(payload.get("digest_points") or 0))
|
||||
except Exception:
|
||||
digest_points = Decimal("0")
|
||||
if digest_points < 0:
|
||||
digest_points = Decimal("0")
|
||||
# 视频复刻·商品:拆镜 Gemini 挂牌已记在 digest_points,与 Seedance 一并预留
|
||||
reserve_amount = reserve_amount + digest_points
|
||||
|
||||
with transaction.atomic():
|
||||
locked = (
|
||||
@@ -671,8 +679,10 @@ def start_pending_free_video(task: AITask) -> AITask:
|
||||
next_payload["estimated_tokens"] = tokens
|
||||
next_payload["review_pending"] = False
|
||||
next_payload.update(video_quote_payload(quote))
|
||||
# 保留拆镜挂牌,结算时加回
|
||||
next_payload["digest_points"] = str(digest_points)
|
||||
locked.request_payload = next_payload
|
||||
locked.estimated_cost = quote.points
|
||||
locked.estimated_cost = quote.points + digest_points
|
||||
locked.status = AITask.Status.RESERVED
|
||||
locked.save(update_fields=["request_payload", "estimated_cost", "status", "updated_at"])
|
||||
|
||||
@@ -992,10 +1002,17 @@ def finalize_free_video(*, task: AITask) -> AITask:
|
||||
except (TypeError, ValueError):
|
||||
total_tokens = 0
|
||||
settle = settle_video_from_payload(actual_model, payload=payload, tokens=total_tokens)
|
||||
try:
|
||||
digest_points = Decimal(str(payload.get("digest_points") or 0))
|
||||
except Exception:
|
||||
digest_points = Decimal("0")
|
||||
if digest_points < 0:
|
||||
digest_points = Decimal("0")
|
||||
if settle.meta.get("rule") == "missing_usage":
|
||||
# estimated_cost 已含 digest_points
|
||||
actual, base_cost = locked.estimated_cost, locked.base_cost
|
||||
else:
|
||||
actual, base_cost = settle.points, settle.base_cost_yuan
|
||||
actual, base_cost = settle.points + digest_points, settle.base_cost_yuan
|
||||
if total_tokens > 0:
|
||||
payload["actual_tokens"] = total_tokens
|
||||
if settle.meta.get("rate"):
|
||||
|
||||
@@ -653,7 +653,24 @@ class VideoDigestBillingTests(TestCase):
|
||||
model_config_id=str(self.model.id),
|
||||
)
|
||||
|
||||
def test_charges_hangpai_points_per_call_when_listed(self):
|
||||
from decimal import Decimal
|
||||
|
||||
from apps.billing.pricing import quote_video_digest
|
||||
|
||||
# unit_price 仍是 10,但挂牌 100 → 扣 100
|
||||
self.model.metadata = {
|
||||
**(self.model.metadata or {}),
|
||||
"points_pricing": {"mode": "per_call", "points_per_call": 100},
|
||||
}
|
||||
self.model.save(update_fields=["metadata"])
|
||||
self.assertEqual(quote_video_digest(model_config=self.model).points, Decimal("100"))
|
||||
self.team.price_multiplier = Decimal("0.80")
|
||||
self.assertEqual(quote_video_digest(team=self.team, model_config=self.model).points, Decimal("80"))
|
||||
self.team.price_multiplier = Decimal("1")
|
||||
|
||||
def test_charges_thirty_points_not_model_unit_price(self):
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from apps.ai.models import AITask
|
||||
|
||||
@@ -1373,9 +1373,9 @@ def digest_asset_video(*, asset, task, model_config_id=None) -> tuple[str, dict]
|
||||
"""把一条已入库的参考视频拆成中文分镜稿,供「视频复刻·商品」当提示词骨架。
|
||||
|
||||
与「提炼提示词」页共用同一份 SKILL.md、同一个 Gemini 3.1 Pro 和同一套质检,
|
||||
保证两处产出一致;区别只在于这里不另建 VIDEO_DIGEST 任务、也不单独扣积分——
|
||||
复刻本来就是一次收费,拆解是它的内部工序。模型调用的审计仍记在传入的复刻
|
||||
task 上(AIModelAttempt),出问题查得到。
|
||||
保证两处产出一致;这里不另建 VIDEO_DIGEST 任务。拆解挂牌积分记在复刻任务的
|
||||
digest_points,与 Seedance 挂牌一并预留/结算。模型调用审计仍记在传入的复刻
|
||||
task 上(AIModelAttempt)。
|
||||
"""
|
||||
import time
|
||||
|
||||
|
||||
@@ -914,7 +914,7 @@ def start_replace_generation(task):
|
||||
def run_replace_digest(task) -> None:
|
||||
"""Worker:参考视频 → 提炼页同款分镜稿 → 一次交给 Seedance。不传原片。
|
||||
|
||||
商品和角色共用。这一步失败 = 整条复刻失败。此时还没预留视频积分,不扣费。
|
||||
商品和角色共用。这一步失败 = 整条复刻失败、不扣费。成功后由 start_pending_free_video 按「Gemini 挂牌 + Seedance 挂牌」一并预留。
|
||||
"""
|
||||
from apps.ai.video_digest import VideoDigestError, digest_asset_video
|
||||
|
||||
@@ -1576,6 +1576,7 @@ def _create_reviewing_task(*, team, user, params: dict, digest_pending: bool = F
|
||||
references = params.get("references") or []
|
||||
billing_duration = int(extra.get("billing_duration") or duration)
|
||||
billing_ratio = str(extra.get("billing_aspect_ratio") or aspect_ratio)
|
||||
# 商品复刻:原片不进 Seedance 引用 → 按无视频引用秒价;角色复刻 references 含视频 → 含引用秒价
|
||||
tokens, quote = quote_video_estimate(
|
||||
model_config,
|
||||
aspect_ratio=billing_ratio,
|
||||
@@ -1585,6 +1586,20 @@ def _create_reviewing_task(*, team, user, params: dict, digest_pending: bool = F
|
||||
team=team,
|
||||
)
|
||||
reserve_amount = video_reserve_amount(quote.points, rule=quote.meta.get("rule"))
|
||||
# 商品复刻另加 Gemini 提炼挂牌(points_per_call;未挂牌回落 30)
|
||||
digest_points = Decimal("0")
|
||||
digest_model_name = ""
|
||||
if digest_pending:
|
||||
from apps.ai.video_digest import resolve_digest_model_config
|
||||
from apps.billing.pricing import quote_video_digest
|
||||
|
||||
digest_model = resolve_digest_model_config()
|
||||
if digest_model is None:
|
||||
raise ValueError("视频提炼模型未配置,请联系管理员")
|
||||
digest_quote = quote_video_digest(team=team, model_config=digest_model)
|
||||
digest_points = Decimal(digest_quote.points)
|
||||
digest_model_name = str(digest_model.name or "")
|
||||
reserve_amount = reserve_amount + digest_points
|
||||
account = CreditAccount.objects.filter(team=team).first()
|
||||
available = (account.balance - account.reserved_balance) if account else Decimal("0")
|
||||
if available < reserve_amount:
|
||||
@@ -1615,6 +1630,9 @@ def _create_reviewing_task(*, team, user, params: dict, digest_pending: bool = F
|
||||
"model_routing_v1": True,
|
||||
"review_pending": True,
|
||||
"digest_pending": digest_pending,
|
||||
# 复刻内拆镜挂牌;start_pending_free_video / settle 会加回预留与实扣
|
||||
"digest_points": str(digest_points),
|
||||
"digest_model": digest_model_name,
|
||||
}
|
||||
for key, value in extra.items():
|
||||
if key in request_payload or value in (None, ""):
|
||||
@@ -1630,7 +1648,7 @@ def _create_reviewing_task(*, team, user, params: dict, digest_pending: bool = F
|
||||
model_config=model_config,
|
||||
idempotency_key=f"free_video:{team.id}:{uuid.uuid4()}",
|
||||
request_payload=request_payload,
|
||||
estimated_cost=quote.points,
|
||||
estimated_cost=quote.points + digest_points,
|
||||
base_cost=Decimal("0"),
|
||||
)
|
||||
if digest_pending:
|
||||
|
||||
@@ -137,9 +137,22 @@ def quote_flat(model_config, *, units: int = 1, team=None) -> Quote:
|
||||
|
||||
|
||||
def quote_video_digest(*, team=None, model_config=None) -> Quote:
|
||||
"""提炼提示词:固定 30 积分/次。失败退还。team 传入则乘团队价格系数。"""
|
||||
"""视频提炼提示词:优先 metadata.points_pricing.points_per_call 挂牌;
|
||||
不吃 unit_price(与旧「固定 30、忽略 unit_price」一致);未挂牌回落固定 30。
|
||||
失败退还。team 传入则乘团队价格系数。"""
|
||||
from apps.billing.points_rules import points_pricing_of, _int_points
|
||||
|
||||
multiplier = team_price_multiplier(team)
|
||||
points = apply_team_price(VIDEO_DIGEST_POINTS, multiplier)
|
||||
listed = None
|
||||
if model_config is not None:
|
||||
listed = _int_points(points_pricing_of(model_config).get("points_per_call"))
|
||||
if listed is not None and listed > 0:
|
||||
unit = Decimal(listed)
|
||||
rule = "per_call"
|
||||
else:
|
||||
unit = VIDEO_DIGEST_POINTS
|
||||
rule = "video_digest_flat"
|
||||
points = apply_team_price(unit, multiplier)
|
||||
base_cost = Decimal("0")
|
||||
if model_config is not None:
|
||||
base_cost = Decimal(str(_pricing_meta(model_config).get("base_cost_yuan") or 0))
|
||||
@@ -147,9 +160,9 @@ def quote_video_digest(*, team=None, model_config=None) -> Quote:
|
||||
points=points,
|
||||
base_cost_yuan=base_cost,
|
||||
meta={
|
||||
"rule": "video_digest_flat",
|
||||
"rule": rule,
|
||||
"units": 1,
|
||||
"unit_points": str(VIDEO_DIGEST_POINTS),
|
||||
"unit_points": str(unit),
|
||||
"price_multiplier": str(multiplier),
|
||||
"rate": str(get_billing_config().points_per_yuan),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user