利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(api): bound video task render resources
Rudy Celekli01ca7b612290
diff --git a/app/models/schema.py b/app/models/schema.pyindex c4eeda84..9dfe58c2 100644--- a/app/models/schema.py+++ b/app/models/schema.py@@ -253,7 +253,11 @@ class VideoSocialMetadataParams:class TaskVideoRequest(VideoParams, BaseModel):- pass+ # Bound API resource requests while leaving the CLI's explicit batch and+ # FFmpeg thread controls in VideoParams unchanged.+ video_count: int = Field(default=1, ge=1, le=5)+ video_clip_duration: int = Field(default=5, ge=1, le=15)+ n_threads: Optional[int] = Field(default=2, ge=1, le=16)class TaskQueryRequest(BaseModel):diff --git a/test/services/test_schema.py b/test/services/test_schema.pyindex 5a7b9f89..dbcf24bf 100644--- a/test/services/test_schema.py+++ b/test/services/test_schema.py@@ -8,7 +8,13 @@ from pydantic import ValidationErrorsys.path.insert(0, str(Path(__file__).parent.parent.parent))from app.models import schema-from app.models.schema import SubtitleRequest, VideoAspect, VideoFitMode, VideoParams+from app.models.schema import (+ SubtitleRequest,+ TaskVideoRequest,+ VideoAspect,+ VideoFitMode,+ VideoParams,+)class TestVideoAspect(unittest.TestCase):@@ -52,6 +58,48 @@ class TestVideoParams(unittest.TestCase):self.assertEqual(params.video_clip_duration, 1)self.assertEqual(params.video_count, 1)+ def test_api_video_count_is_bounded_without_limiting_cli_params(self):+ """One HTTP task must not schedule an unbounded render batch."""+ self.assertEqual(+ TaskVideoRequest(video_subject="Coffee", video_count=5).video_count, 5+ )+ with self.assertRaises(ValidationError):+ TaskVideoRequest(video_subject="Coffee", video_count=6)++ # The shared model also powers the CLI, which documents any positive+ # count, so its existing behavior must remain available there.+ self.assertEqual(+ VideoParams(video_subject="Coffee", video_count=6).video_count, 6+ )++ def test_api_render_threads_are_bounded_without_limiting_cli_params(self):+ """An HTTP caller cannot pass arbitrary FFmpeg thread counts."""+ self.assertEqual(+ TaskVideoRequest(video_subject="Coffee", n_threads=16).n_threads, 16+ )+ for value in (0, -1, 17):+ with self.subTest(value=value):+ with self.assertRaises(ValidationError):+ TaskVideoRequest(video_subject="Coffee", n_threads=value)++ self.assertEqual(+ VideoParams(video_subject="Coffee", n_threads=17).n_threads, 17+ )++ def test_api_clip_duration_is_bounded_without_limiting_cli_params(self):+ """The API keeps one clip within the WebUI provider duration range."""+ self.assertEqual(+ TaskVideoRequest(video_subject="Coffee", video_clip_duration=15).video_clip_duration,+ 15,+ )+ with self.assertRaises(ValidationError):+ TaskVideoRequest(video_subject="Coffee", video_clip_duration=16)++ self.assertEqual(+ VideoParams(video_subject="Coffee", video_clip_duration=16).video_clip_duration,+ 16,+ )+def test_subtitle_modes_accept_only_supported_api_values(self):"""新增字幕参数必须拒绝拼写错误,避免请求成功后静默降级。"""params = VideoParams(