API接口支持模板自定义参数

This commit is contained in:
puke
2025-12-17 10:58:27 +08:00
parent cbbd85edda
commit f3e0d0d771
4 changed files with 120 additions and 4 deletions

View File

@@ -14,7 +14,7 @@
Frame/Template rendering API schemas
"""
from typing import Optional
from typing import Optional, Dict, Any, List
from pydantic import BaseModel, Field
@@ -47,3 +47,23 @@ class FrameRenderResponse(BaseModel):
width: int = Field(..., description="Frame width in pixels")
height: int = Field(..., description="Frame height in pixels")
class TemplateParamConfig(BaseModel):
"""Single template parameter configuration"""
type: str = Field(..., description="Parameter type: 'text', 'number', 'color', 'bool'")
default: Any = Field(..., description="Default value")
label: str = Field(..., description="Display label for the parameter")
class TemplateParamsResponse(BaseModel):
"""Template parameters response"""
success: bool = True
message: str = "Success"
template: str = Field(..., description="Template path")
media_width: int = Field(..., description="Media width from template meta tags")
media_height: int = Field(..., description="Media height from template meta tags")
params: Dict[str, TemplateParamConfig] = Field(
default_factory=dict,
description="Custom parameters defined in template. Key is parameter name, value is config."
)

View File

@@ -14,7 +14,7 @@
Video generation API schemas
"""
from typing import Optional, Literal
from typing import Optional, Literal, Dict, Any
from pydantic import BaseModel, Field
@@ -69,6 +69,13 @@ class VideoGenerateRequest(BaseModel):
description="HTML template path with size (e.g., '1080x1920/default.html'). Video size is auto-determined from template."
)
# === Template Custom Parameters ===
template_params: Optional[Dict[str, Any]] = Field(
None,
description="Custom template parameters (e.g., {'accent_color': '#ff0000', 'background': 'url'}). "
"Available parameters depend on the template. Use GET /api/templates/{template_path}/params to discover them."
)
# === Image Style ===
prompt_prefix: Optional[str] = Field(None, description="Image style prefix")
@@ -82,7 +89,11 @@ class VideoGenerateRequest(BaseModel):
"text": "Atomic Habits teaches us that small changes compound over time to produce remarkable results.",
"mode": "generate",
"n_scenes": 5,
"voice_id": "[Chinese] zh-CN Yunjian",
"frame_template": "1080x1920/image_default.html",
"template_params": {
"accent_color": "#3498db",
"background": "https://example.com/custom-bg.jpg"
},
"title": "The Power of Atomic Habits"
}
}