From eaa7e9b1f095ce537e592e22526b03dba816f105 Mon Sep 17 00:00:00 2001 From: Nam Vu Date: Sun, 22 Sep 2024 13:02:12 +0700 Subject: [PATCH] fix: llm_generator.py JSONDecodeError (#8504) --- api/core/llm_generator/llm_generator.py | 2 ++ .../workflow/nodes/question_classifier/template_prompts.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/core/llm_generator/llm_generator.py b/api/core/llm_generator/llm_generator.py index 78a6d6e683..39bd6fee69 100644 --- a/api/core/llm_generator/llm_generator.py +++ b/api/core/llm_generator/llm_generator.py @@ -47,6 +47,8 @@ class LLMGenerator: ) answer = response.message.content cleaned_answer = re.sub(r"^.*(\{.*\}).*$", r"\1", answer, flags=re.DOTALL) + if cleaned_answer is None: + return "" result_dict = json.loads(cleaned_answer) answer = result_dict["Your Output"] name = answer.strip() diff --git a/api/core/workflow/nodes/question_classifier/template_prompts.py b/api/core/workflow/nodes/question_classifier/template_prompts.py index ce32b01aa4..4bca2d9dd4 100644 --- a/api/core/workflow/nodes/question_classifier/template_prompts.py +++ b/api/core/workflow/nodes/question_classifier/template_prompts.py @@ -2,9 +2,9 @@ QUESTION_CLASSIFIER_SYSTEM_PROMPT = """ ### Job Description', You are a text classification engine that analyzes text data and assigns categories based on user input or automatically determined categories. ### Task - Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output.Additionally, you need to extract the key words from the text that are related to the classification. + Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output. Additionally, you need to extract the key words from the text that are related to the classification. ### Format - The input text is in the variable input_text.Categories are specified as a category list with two filed category_id and category_name in the variable categories .Classification instructions may be included to improve the classification accuracy. + The input text is in the variable input_text. Categories are specified as a category list with two filed category_id and category_name in the variable categories. Classification instructions may be included to improve the classification accuracy. ### Constraint DO NOT include anything other than the JSON array in your response. ### Memory @@ -52,7 +52,7 @@ QUESTION_CLASSIFIER_COMPLETION_PROMPT = """ ### Job Description You are a text classification engine that analyzes text data and assigns categories based on user input or automatically determined categories. ### Task -Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output. Additionally, you need to extract the key words from the text that are related to the classification. +Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output. Additionally, you need to extract the key words from the text that are related to the classification. ### Format The input text is in the variable input_text. Categories are specified as a category list with two filed category_id and category_name in the variable categories. Classification instructions may be included to improve the classification accuracy. ### Constraint