利用 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(task): preserve literal error text in custom scripts
Rudy Celeklib536b27d0e19
diff --git a/app/services/task.py b/app/services/task.pyindex 6652623f..8dd43342 100644--- a/app/services/task.py+++ b/app/services/task.py@@ -1505,10 +1505,18 @@ def _run_pipeline(# 1. Generate scriptvideo_script = generate_script(task_id, params)- if not video_script or "Error: " in video_script:+ # The LLM adapter uses a leading "Error: " as its failure sentinel. A+ # user-provided script may legitimately quote that text anywhere, including+ # at the beginning, so only interpret it for an LLM-generated script.+ is_provider_error = (+ not (params.video_script or "").strip()+ and isinstance(video_script, str)+ and video_script.startswith("Error: ")+ )+ if not video_script or is_provider_error:error = (video_script.removeprefix("Error: ").strip()- if isinstance(video_script, str) and "Error: " in video_script+ if is_provider_errorelse "failed to generate video script")return _mark_task_failed(task_id, "script", error)diff --git a/test/services/test_task.py b/test/services/test_task.pyindex f24f5643..46e266e1 100644--- a/test/services/test_task.py+++ b/test/services/test_task.py@@ -343,6 +343,39 @@ class TestTaskService(unittest.TestCase):generate_script.assert_called_once()self.assertEqual(result, {"script": "脚本"})+ def test_custom_script_keeps_literal_error_text(self):+ """A user's narration about errors is not an LLM provider failure."""+ scripts = (+ "The server logged Error: 404 before the page loaded.",+ "Error: 404 is the status shown when a page is missing.",+ )+ for index, script in enumerate(scripts):+ with self.subTest(script=script):+ task_id = f"literal-error-script-{index}"+ state = MemoryState()+ params = VideoParams(video_subject="debugging", video_script=script)+ with patch.object(tm.sm, "state", state):+ result = tm.start(task_id, params, stop_at="script")++ self.assertEqual(result, {"script": script})+ self.assertEqual(+ state.get_task(task_id)["state"], tm.const.TASK_STATE_COMPLETE+ )++ def test_generated_script_still_rejects_provider_error_prefix(self):+ """The provider's error sentinel must still stop generated scripts."""+ state = MemoryState()+ params = VideoParams(video_subject="debugging")+ with (+ patch.object(tm, "generate_script", return_value="Error: invalid API key"),+ patch.object(tm.sm, "state", state),+ ):+ result = tm.start("generated-script-error", params, stop_at="script")++ self.assertEqual(result["state"], tm.const.TASK_STATE_FAILED)+ self.assertEqual(result["failed_stage"], "script")+ self.assertEqual(result["error"], "invalid API key")+def test_run_pipeline_skips_ffmpeg_check_for_terms_stage(self):"""搜索词阶段同样不需要 FFmpeg,不应触发探测。"""params = VideoParams(video_subject="test")