From fc6844dd19210615d36bcf85c2413caa487a6c08 Mon Sep 17 00:00:00 2001 From: harry Date: Fri, 17 May 2024 17:11:35 +0800 Subject: [PATCH] enhanced exception handling for generating terms --- app/services/llm.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/services/llm.py b/app/services/llm.py index 5177779..ac05137 100644 --- a/app/services/llm.py +++ b/app/services/llm.py @@ -295,6 +295,7 @@ Please note that you must use English for generating video search terms; Chinese logger.info(f"subject: {video_subject}") search_terms = [] + response = "" for i in range(_max_retries): try: response = _generate_response(prompt) @@ -304,12 +305,15 @@ Please note that you must use English for generating video search terms; Chinese continue except Exception as e: - match = re.search(r'\[.*]', response) - if match: - try: - search_terms = json.loads(match.group()) - except json.JSONDecodeError: - pass + logger.warning(f"failed to generate video terms: {str(e)}") + if response: + match = re.search(r'\[.*]', response) + if match: + try: + search_terms = json.loads(match.group()) + except Exception as e: + logger.warning(f"failed to generate video terms: {str(e)}") + pass if search_terms and len(search_terms) > 0: break