mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-06 02:46:40 +00:00
fix(ChatExcel): ChatExcel OutParse Bug Fix
1.ChatExcel OutParse Bug Fix
This commit is contained in:
parent
cad2785d94
commit
f19ee46e74
@ -141,7 +141,6 @@ class BaseOutputParser(ABC):
|
|||||||
if not temp_json:
|
if not temp_json:
|
||||||
temp_json = self.__json_interception(s)
|
temp_json = self.__json_interception(s)
|
||||||
|
|
||||||
|
|
||||||
temp_json = self.__illegal_json_ends(temp_json)
|
temp_json = self.__illegal_json_ends(temp_json)
|
||||||
return temp_json
|
return temp_json
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -154,7 +153,7 @@ class BaseOutputParser(ABC):
|
|||||||
if i < 0:
|
if i < 0:
|
||||||
return ""
|
return ""
|
||||||
count = 1
|
count = 1
|
||||||
for j, c in enumerate(s[i + 1:], start=i + 1):
|
for j, c in enumerate(s[i + 1 :], start=i + 1):
|
||||||
if c == "]":
|
if c == "]":
|
||||||
count -= 1
|
count -= 1
|
||||||
elif c == "[":
|
elif c == "[":
|
||||||
@ -162,13 +161,13 @@ class BaseOutputParser(ABC):
|
|||||||
if count == 0:
|
if count == 0:
|
||||||
break
|
break
|
||||||
assert count == 0
|
assert count == 0
|
||||||
return s[i: j + 1]
|
return s[i : j + 1]
|
||||||
else:
|
else:
|
||||||
i = s.find("{")
|
i = s.find("{")
|
||||||
if i < 0:
|
if i < 0:
|
||||||
return ""
|
return ""
|
||||||
count = 1
|
count = 1
|
||||||
for j, c in enumerate(s[i + 1:], start=i + 1):
|
for j, c in enumerate(s[i + 1 :], start=i + 1):
|
||||||
if c == "}":
|
if c == "}":
|
||||||
count -= 1
|
count -= 1
|
||||||
elif c == "{":
|
elif c == "{":
|
||||||
@ -176,7 +175,7 @@ class BaseOutputParser(ABC):
|
|||||||
if count == 0:
|
if count == 0:
|
||||||
break
|
break
|
||||||
assert count == 0
|
assert count == 0
|
||||||
return s[i: j + 1]
|
return s[i : j + 1]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@ -195,9 +194,9 @@ class BaseOutputParser(ABC):
|
|||||||
# if "```" in cleaned_output:
|
# if "```" in cleaned_output:
|
||||||
# cleaned_output, _ = cleaned_output.split("```")
|
# cleaned_output, _ = cleaned_output.split("```")
|
||||||
if cleaned_output.startswith("```json"):
|
if cleaned_output.startswith("```json"):
|
||||||
cleaned_output = cleaned_output[len("```json"):]
|
cleaned_output = cleaned_output[len("```json") :]
|
||||||
if cleaned_output.startswith("```"):
|
if cleaned_output.startswith("```"):
|
||||||
cleaned_output = cleaned_output[len("```"):]
|
cleaned_output = cleaned_output[len("```") :]
|
||||||
if cleaned_output.endswith("```"):
|
if cleaned_output.endswith("```"):
|
||||||
cleaned_output = cleaned_output[: -len("```")]
|
cleaned_output = cleaned_output[: -len("```")]
|
||||||
cleaned_output = cleaned_output.strip()
|
cleaned_output = cleaned_output.strip()
|
||||||
@ -206,9 +205,9 @@ class BaseOutputParser(ABC):
|
|||||||
cleaned_output = self.__extract_json(cleaned_output)
|
cleaned_output = self.__extract_json(cleaned_output)
|
||||||
cleaned_output = (
|
cleaned_output = (
|
||||||
cleaned_output.strip()
|
cleaned_output.strip()
|
||||||
.replace("\\n", " ")
|
.replace("\\n", " ")
|
||||||
.replace("\n", " ")
|
.replace("\n", " ")
|
||||||
.replace("\\", " ")
|
.replace("\\", " ")
|
||||||
)
|
)
|
||||||
cleaned_output = self.__illegal_json_ends(cleaned_output)
|
cleaned_output = self.__illegal_json_ends(cleaned_output)
|
||||||
return cleaned_output
|
return cleaned_output
|
||||||
|
@ -38,8 +38,7 @@ class ChatExcelOutputParser(BaseOutputParser):
|
|||||||
display = response[key]
|
display = response[key]
|
||||||
return ExcelAnalyzeResponse(sql, thoughts, display)
|
return ExcelAnalyzeResponse(sql, thoughts, display)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(f"LLM Response Can't Parser! \n{ model_out_text}" )
|
raise ValueError(f"LLM Response Can't Parser! \n{ model_out_text}")
|
||||||
|
|
||||||
|
|
||||||
def parse_view_response(self, speak, data) -> str:
|
def parse_view_response(self, speak, data) -> str:
|
||||||
### tool out data to table view
|
### tool out data to table view
|
||||||
|
Loading…
Reference in New Issue
Block a user