diff --git a/pilot/out_parser/base.py b/pilot/out_parser/base.py index 2d080c3fe..abd4d304b 100644 --- a/pilot/out_parser/base.py +++ b/pilot/out_parser/base.py @@ -129,44 +129,55 @@ def __illegal_json_ends(self, s): return temp_json def __extract_json(self, s): - temp_json = self.__json_interception(s, True) - if not temp_json: - temp_json = self.__json_interception(s) try: + # Get the dual-mode analysis first and get the maximum result + temp_json_simple = self.__json_interception(s) + temp_json_array = self.__json_interception(s, True) + if len(temp_json_simple) > len(temp_json_array): + temp_json = temp_json_simple + else: + temp_json = temp_json_array + + if not temp_json: + temp_json = self.__json_interception(s) + temp_json = self.__illegal_json_ends(temp_json) return temp_json except Exception as e: - raise ValueError("Failed to find a valid json responseļ¼" + temp_json) + raise ValueError("Failed to find a valid json in LLM responseļ¼" + temp_json) def __json_interception(self, s, is_json_array: bool = False): - if is_json_array: - i = s.find("[") - if i < 0: - return None - count = 1 - for j, c in enumerate(s[i + 1 :], start=i + 1): - if c == "]": - count -= 1 - elif c == "[": - count += 1 - if count == 0: - break - assert count == 0 - return s[i : j + 1] - else: - i = s.find("{") - if i < 0: - return None - count = 1 - for j, c in enumerate(s[i + 1 :], start=i + 1): - if c == "}": - count -= 1 - elif c == "{": - count += 1 - if count == 0: - break - assert count == 0 - return s[i : j + 1] + try: + if is_json_array: + i = s.find("[") + if i < 0: + return "" + count = 1 + for j, c in enumerate(s[i + 1 :], start=i + 1): + if c == "]": + count -= 1 + elif c == "[": + count += 1 + if count == 0: + break + assert count == 0 + return s[i : j + 1] + else: + i = s.find("{") + if i < 0: + return "" + count = 1 + for j, c in enumerate(s[i + 1 :], start=i + 1): + if c == "}": + count -= 1 + elif c == "{": + count += 1 + if count == 0: + break + assert count == 0 + return s[i : j + 1] + except Exception as e: + return "" def parse_prompt_response(self, model_out_text) -> T: """ diff --git a/pilot/scene/chat_data/chat_excel/excel_analyze/out_parser.py b/pilot/scene/chat_data/chat_excel/excel_analyze/out_parser.py index 3e5dfa68a..88cce3d68 100644 --- a/pilot/scene/chat_data/chat_excel/excel_analyze/out_parser.py +++ b/pilot/scene/chat_data/chat_excel/excel_analyze/out_parser.py @@ -27,15 +27,18 @@ def __init__(self, sep: str, is_stream_out: bool): def parse_prompt_response(self, model_out_text): clean_str = super().parse_prompt_response(model_out_text) print("clean prompt response:", clean_str) - response = json.loads(clean_str) - for key in sorted(response): - if key.strip() == "sql": - sql = response[key] - if key.strip() == "thoughts": - thoughts = response[key] - if key.strip() == "display": - display = response[key] - return ExcelAnalyzeResponse(sql, thoughts, display) + try: + response = json.loads(clean_str) + for key in sorted(response): + if key.strip() == "sql": + sql = response[key] + if key.strip() == "thoughts": + thoughts = response[key] + if key.strip() == "display": + display = response[key] + return ExcelAnalyzeResponse(sql, thoughts, display) + except Exception as e: + raise ValueError(f"LLM Response Can't Parser! \n{ model_out_text}") def parse_view_response(self, speak, data) -> str: ### tool out data to table view diff --git a/pilot/scene/chat_data/chat_excel/excel_learning/out_parser.py b/pilot/scene/chat_data/chat_excel/excel_learning/out_parser.py index b4dece331..0d636c16d 100644 --- a/pilot/scene/chat_data/chat_excel/excel_learning/out_parser.py +++ b/pilot/scene/chat_data/chat_excel/excel_learning/out_parser.py @@ -41,7 +41,7 @@ def parse_prompt_response(self, model_out_text): return model_out_text def parse_view_response(self, speak, data) -> str: - if data: + if data and not isinstance(data, str): ### tool out data to table view html_title = f"### **Data Summary**\n{data.desciption} " html_colunms = f"### **Data Structure**\n" diff --git a/pilot/server/static/404.html b/pilot/server/static/404.html index 966f5bb82..cda6129d2 100644 --- a/pilot/server/static/404.html +++ b/pilot/server/static/404.html @@ -1 +1 @@ -