36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from fastapi import HTTPException
|
|
|
|
from app.services.module_generation_step_common_service import build_file_url_or_data_uri
|
|
|
|
|
|
def build_v2_video_generation_references(material_payload: dict[str, Any]) -> list[dict[str, Any]]:
|
|
"""V2 最终视频只能携带可选素材图片,绝不携带素材视频/音频。"""
|
|
image_url = str(material_payload.get("material_image_url") or "").strip()
|
|
if not image_url:
|
|
return []
|
|
return [
|
|
{
|
|
"type": "image",
|
|
"url": build_file_url_or_data_uri(image_url),
|
|
"name": "素材参考图片",
|
|
"upload_resource_id": material_payload.get("material_image_resource_id"),
|
|
"role": "reference_image",
|
|
}
|
|
]
|
|
|
|
|
|
def assert_v2_video_generation_references(references: list[dict[str, Any]]) -> None:
|
|
image_count = 0
|
|
for item in references:
|
|
media_type = str(item.get("type") or item.get("media_type") or "").lower()
|
|
if media_type == "image":
|
|
image_count += 1
|
|
continue
|
|
raise HTTPException(status_code=400, detail="V2 视频生成只允许携带一张素材图片,禁止视频或音频附件")
|
|
if image_count > 1:
|
|
raise HTTPException(status_code=400, detail="V2 视频生成最多携带一张素材图片")
|