fix(viral-video): 修复call_llm传list bug 改为直接chat_completion
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m3s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Failing after 50s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m51s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m6s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m38s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 3m13s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 3m44s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m48s
CI/CD Pipeline / Validate - Style (pull_request) Failing after 6m17s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 7m15s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m14s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 8m59s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Failing after 2s
AI Code Review / AI Code Review (pull_request) Successful in 10m51s

审计发现 _step_intent_parsing(L482) 和 _step_script_generation(L867) 两处
把 messages list 当作第一个位置参数传给 call_llm(prompt:str,...),
list被repr成字符串再套一层默认system_prompt,实际发给豆包的消息结构异常。

修复:
- 改为直接用 get_doubao_client().chat_completion(messages,...),
  与 reviewer.py/generator.py 调用方式一致
- 增加 is_available 预检,不可用时直接走fallback(意图解析默认dict / _fallback_script)
- 不再走 call_llm 字符串包装层

本次PR同时包含#2214 timeout调优(cherry-pick):
- fast_json _DEFAULT_TIMEOUT 12→15s
- fast_path _FAST_TIMEOUT/_FAST_JSON_TIMEOUT 12→15s
- pro fallback _DEFAULT_TIMEOUT 25→30s,外层_PRO_TIMEOUT 25→30s
- 保留环境变量覆盖能力
This commit is contained in:
xiaoxia
2026-10-06 00:41:31 +08:00
parent cdf3ef360b
commit 80103f8c6d
+13 -5
View File
@@ -421,10 +421,14 @@ def _step_intent_parsing(job: ViralVideoJob, image_analysis: dict) -> dict:
render_system_prompt,
render_user_prompt,
)
from packages.shared.ai_service import call_llm
from packages.shared.ai_client import get_doubao_client
except ImportError:
return {"intent": "推广产品", "key_messages": ["产品亮点"], "tone": "专业", "suggested_title": ""}
_llm_client = get_doubao_client()
if not _llm_client.is_available:
return {"intent": "推广产品", "key_messages": ["产品亮点"], "tone": "专业", "suggested_title": ""}
products_summary = ""
products = (image_analysis or {}).get("products", []) or []
for p in products:
@@ -479,13 +483,13 @@ def _step_intent_parsing(job: ViralVideoJob, image_analysis: dict) -> dict:
for _m, _lbl in [(_fast, "fast"), (_pro, "pro-fallback")]:
try:
logger.info("[爆款视频] 意图解析 model=%s label=%s", _m, _lbl)
raw = call_llm(
raw = _llm_client.chat_completion(
[{"role": "system", "content": system}, {"role": "user", "content": user}],
temperature=0.4,
max_tokens=1024,
model=_m,
timeout=60,
) # #2180: 意图解析 LLM 实测需更长响应,原25s太紧
) # #2180/#2215: 直接用 client.chat_completion 传 messages list,不再走 call_llm 字符串包装
if not raw:
continue
parsed = _parse(raw)
@@ -825,10 +829,14 @@ def _step_script_generation(job: ViralVideoJob, intent: dict, image_analysis: di
GLOBAL_CONSTRAINTS,
NEGATIVE_RULES,
)
from packages.shared.ai_service import call_llm
from packages.shared.ai_client import get_doubao_client
except ImportError:
return _fallback_script(job)
_llm_client2 = get_doubao_client()
if not _llm_client2.is_available:
return _fallback_script(job)
products_summary = _build_products_summary(image_analysis)
dur = max(5, min(30, int(getattr(job, "duration", 15) or 15)))
@@ -864,7 +872,7 @@ def _step_script_generation(job: ViralVideoJob, intent: dict, image_analysis: di
def _try_gen(model: str, temp: float, max_tok: int, label: str, tmo: int = 25):
logger.info("[爆款视频] 编导脚本生成 model=%s label=%s timeout=%d", model, label, tmo)
raw = call_llm(
raw = _llm_client2.chat_completion(
[{"role": "system", "content": system_tpl}, {"role": "user", "content": user}],
temperature=temp,
max_tokens=max_tok,