利用 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(llm): suppress spurious retry warning on the final attempt
MihirPbb29f3495939
diff --git a/app/services/llm.py b/app/services/llm.pyindex 37fc53a7..54658d21 100644--- a/app/services/llm.py+++ b/app/services/llm.py@@ -569,7 +569,7 @@ def generate_script(except Exception as e:logger.error(f"failed to generate script: {e}")- if i < _max_retries:+ if i < _max_retries - 1:logger.warning(f"failed to generate video script, trying again... {i + 1}")if "Error: " in final_script:logger.error(f"failed to generate video script: {final_script}")@@ -695,7 +695,7 @@ Please note that you must use English for generating video search terms; Chineseif search_terms and len(search_terms) > 0:break- if i < _max_retries:+ if i < _max_retries - 1:logger.warning(f"failed to generate video terms, trying again... {i + 1}")logger.success(f"completed: \n{search_terms}")diff --git a/test/services/test_llm.py b/test/services/test_llm.pyindex 177b37b7..283af0ad 100644--- a/test/services/test_llm.py+++ b/test/services/test_llm.py@@ -1736,5 +1736,55 @@ class TestLiteLLMLiveIntegration(unittest.TestCase):self.assertIn("4", result)+class TestRetryWarningBoundary(unittest.TestCase):+ """'trying again' must not be logged on the last retry attempt."""++ def _trying_again_count(self, mock_logger: object, fragment: str) -> int:+ return sum(+ 1+ for call in mock_logger.warning.call_args_list+ if fragment in str(call)+ )++ def test_generate_script_no_spurious_warning_on_last_attempt(self):+ with (+ patch.object(+ llm,+ "_generate_response",+ side_effect=RuntimeError("provider unavailable"),+ ),+ patch.object(llm, "logger") as mock_logger,+ ):+ llm.generate_script(video_subject="test subject")++ count = self._trying_again_count(mock_logger, "trying again")+ self.assertEqual(+ count,+ llm._max_retries - 1,+ "Warning must not fire on the final attempt — no further retry will occur",+ )++ def test_generate_terms_no_spurious_warning_on_last_attempt(self):+ with (+ patch.object(+ llm,+ "_generate_response",+ side_effect=RuntimeError("provider unavailable"),+ ),+ patch.object(llm, "logger") as mock_logger,+ ):+ llm.generate_terms(+ video_subject="test subject",+ video_script="some script text",+ )++ count = self._trying_again_count(mock_logger, "trying again")+ self.assertEqual(+ count,+ llm._max_retries - 1,+ "Warning must not fire on the final attempt — no further retry will occur",+ )++if __name__ == "__main__":unittest.main()