Skip to content

Commit

Permalink
fix(ChatExcel): ChatExcel OutParse Bug Fix (#588)
Browse files Browse the repository at this point in the history
1.ChatExcel OutParse Bug Fix
  • Loading branch information
Aries-ckt authored Sep 14, 2023
2 parents 465c065 + f19ee46 commit 9cc94b6
Show file tree
Hide file tree
Showing 47 changed files with 321 additions and 300 deletions.
75 changes: 43 additions & 32 deletions pilot/out_parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
21 changes: 12 additions & 9 deletions pilot/scene/chat_data/chat_excel/excel_analyze/out_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pilot/server/static/404.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pilot/server/static/404/index.html

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pilot/server/static/_next/static/chunks/161.0385a2869c97f681.js

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions pilot/server/static/_next/static/chunks/161.a5c14a073f98c4a9.js

This file was deleted.

39 changes: 0 additions & 39 deletions pilot/server/static/_next/static/chunks/196-48d8c6ab3e99146c.js

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pilot/server/static/_next/static/chunks/34-52d4d2d11bef48dc.js

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions pilot/server/static/_next/static/chunks/34-c924e44753dd2c5b.js

This file was deleted.

30 changes: 30 additions & 0 deletions pilot/server/static/_next/static/chunks/378-dbd26a0c14558f18.js

Large diffs are not rendered by default.

This file was deleted.

30 changes: 0 additions & 30 deletions pilot/server/static/_next/static/chunks/455-597a8a48388a0d9b.js

This file was deleted.

19 changes: 19 additions & 0 deletions pilot/server/static/_next/static/chunks/542-f4cda9df864aa7ed.js

Large diffs are not rendered by default.

This file was deleted.

Loading

0 comments on commit 9cc94b6

Please sign in to comment.