refactor(question_classifier): improve error handling with custom exceptions (#10365)

This commit is contained in:
-LAN-
2024-11-07 14:02:30 +08:00
committed by GitHub
parent 1ccca7cc68
commit d3e9930235
3 changed files with 11 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ def parse_json_markdown(json_string: str) -> dict:
starts = ["```json", "```", "``", "`", "{"]
ends = ["```", "``", "`", "}"]
end_index = -1
start_index = 0
for s in starts:
start_index = json_string.find(s)
if start_index != -1:
@@ -24,7 +25,6 @@ def parse_json_markdown(json_string: str) -> dict:
break
if start_index != -1 and end_index != -1 and start_index < end_index:
extracted_content = json_string[start_index:end_index].strip()
print("content:", extracted_content, start_index, end_index)
parsed = json.loads(extracted_content)
else:
raise Exception("Could not find JSON block in the output.")