Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(api): bound ordered term request size

Rudy Celekli597d34f8ffae
diff --git a/app/models/schema.py b/app/models/schema.py
index 9fa6e902..c4eeda84 100644
--- a/app/models/schema.py
+++ b/app/models/schema.py
@@ -265,7 +265,9 @@ class VideoScriptRequest(VideoScriptParams, BaseModel):
class VideoTermsRequest(VideoTermsParams, BaseModel):
- pass
+ # Ordered term generation allocates an example list proportional to amount
+ # before contacting the model. Reject malformed or excessive API requests.
+ amount: int = Field(default=5, ge=1, le=50)
class VideoSocialMetadataRequest(VideoSocialMetadataParams, BaseModel):
diff --git a/test/services/test_controller_llm.py b/test/services/test_controller_llm.py
index 69e9c382..e128ebad 100644
--- a/test/services/test_controller_llm.py
+++ b/test/services/test_controller_llm.py
@@ -1,6 +1,8 @@
import unittest
from unittest.mock import patch
+from pydantic import ValidationError
+
from app.controllers.v1 import llm as llm_controller
from app.models.schema import (
VideoScriptRequest,
@@ -10,6 +12,19 @@ from app.models.schema import (
class TestLlmController(unittest.TestCase):
+ def test_terms_request_bounds_generated_term_count(self):
+ """Ordered term prompts must not allocate arbitrary-length examples."""
+ self.assertEqual(
+ VideoTermsRequest(amount=50, match_materials_to_script=True).amount,
+ 50,
+ )
+ for value in (0, -1, 51, None):
+ with self.subTest(value=value):
+ with self.assertRaises(ValidationError):
+ VideoTermsRequest(
+ amount=value, match_materials_to_script=True
+ )
+
def test_generate_video_script_forwards_all_prompt_fields(self):
"""文案接口不能丢失高级提示词或段落数量。"""
body = VideoScriptRequest(