爆款开头API开发完成文件追加

This commit is contained in:
2026-06-10 15:23:03 +08:00
parent b4a9ca9e9b
commit fa2e298efa
12 changed files with 115 additions and 11 deletions
@@ -13,6 +13,8 @@ from app.services.generation_refund_service import mark_chat_generation_task_fai
from app.services.generation_provider_service import create_provider_task
from app.tasks.celery_app import celery_app
ALLOWED_GENERATION_MODES = {"chatapi_async", "hot_opening_replicate"}
def _get_first_value(obj: Any, *field_names: str) -> Optional[Any]:
"""
@@ -63,6 +65,14 @@ def _build_optimized_prompt_by_params(task: ChatGenerationTask) -> str:
base_prompt = original_prompt.rstrip(",。;; \n\t")
gen_type = (_to_clean_str(getattr(task, "gen_type", None)) or "").lower()
generation_mode = _to_clean_str(getattr(task, "generation_mode", None)) or ""
# 爆款开头复刻第5步的视频生成,original_prompt 已经是视频提词 JSON schema。
# 不能再追加“时长/比例/分辨率”中文参数,否则会污染 schema。
if generation_mode == "hot_opening_replicate" and gen_type == "video":
stripped = base_prompt.strip()
if stripped.startswith("{") or stripped.startswith("["):
return base_prompt
duration = _get_first_value(task, "duration")
aspect_ratio = _get_first_value(task, "aspect_ratio")
@@ -113,7 +123,7 @@ async def _run(task_id: str):
).with_for_update().limit(1))
task = result.scalar_one_or_none()
if not task or task.generation_mode != "chatapi_async":
if not task or task.generation_mode not in ALLOWED_GENERATION_MODES:
return
if task.status != "generating":
@@ -128,6 +138,9 @@ async def _run(task_id: str):
)
await db.commit()
await log_task_event(task, event_type="TASK_TIMEOUT", to_status="failed", to_stage="timeout")
from app.services.generation_module_hook_service import notify_chat_generation_task_finished
await notify_chat_generation_task_finished(db, task)
await db.commit()
return
if task.pipeline_stage not in ("queued", "preparing", "creating_provider_task"):
@@ -253,6 +266,9 @@ async def _run(task_id: str):
)
await db.commit()
await log_task_event(task, event_type="TASK_FAILED", message=task.error_message)
from app.services.generation_module_hook_service import notify_chat_generation_task_finished
await notify_chat_generation_task_finished(db, task)
await db.commit()
if celery_app: