From c08cfcd5c1f4e99da48e8a7f7cff1e63dcfdafbf Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Sat, 3 Oct 2026 01:31:21 +0800 Subject: [PATCH] =?UTF-8?q?chore(points):=20worker=20settle=20=E9=98=B6?= =?UTF-8?q?=E6=AE=B5=E6=89=93=E5=8D=B0=E9=A2=84=E4=BC=B0/=E5=AE=9E?= =?UTF-8?q?=E9=99=85=20tokens=20diff=20=E4=BE=BF=E4=BA=8E=E5=85=AC?= =?UTF-8?q?=E5=BC=8F=E6=A0=A1=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上线后可通过日志对比 formula 预估 tokens 与 Seedance 返回的 completion_tokens,误差应在 10% 以内(视频编码余量)。 --- apps/worker/worker_app/tasks/viral_video.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/worker/worker_app/tasks/viral_video.py b/apps/worker/worker_app/tasks/viral_video.py index 8adc448c2..34d3fd54d 100644 --- a/apps/worker/worker_app/tasks/viral_video.py +++ b/apps/worker/worker_app/tasks/viral_video.py @@ -1615,13 +1615,26 @@ def _settle_viral_video(job: ViralVideoJob, usage: dict | None) -> None: getattr(job, "video_resolution", "720p") or "720p", getattr(job, "video_ratio", "9:16") or "9:16", ) + fps = 24 + duration = int(getattr(job, "duration", 15) or 15) + est_tokens = duration * w * h * fps // 1024 actual_tokens = None if isinstance(usage, dict): at = usage.get("completion_tokens") if isinstance(at, (int, float)) and at > 0: actual_tokens = int(at) + diff_pct = None + if actual_tokens and est_tokens > 0: + diff_pct = (actual_tokens - est_tokens) * 100.0 / est_tokens + logger.info( + "[爆款视频] tokens估算vs实际 job_id=%s duration=%s %sx%s model=%s est=%s actual=%s diff=%.1f%%", + job.id, duration, w, h, + getattr(job, "video_model", "seedance-2.5"), + est_tokens, actual_tokens, + diff_pct if diff_pct is not None else 0.0, + ) actual_credits = calculate_viral_video_credits( - int(getattr(job, "duration", 15) or 15), + duration, w, h, getattr(job, "video_model", "") or "seedance-2.5",