mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
feat: fix json end with `` (#285)
This commit is contained in:
parent
2478c88e07
commit
19b5cb1e10
|
@ -13,6 +13,12 @@ def parse_json_markdown(json_string: str) -> dict:
|
||||||
if start_index != -1 and end_index != -1:
|
if start_index != -1 and end_index != -1:
|
||||||
extracted_content = json_string[start_index + len("```json"):end_index].strip()
|
extracted_content = json_string[start_index + len("```json"):end_index].strip()
|
||||||
|
|
||||||
|
# Parse the JSON string into a Python dictionary
|
||||||
|
parsed = json.loads(extracted_content)
|
||||||
|
elif start_index != -1 and end_index == -1 and json_string.endswith("``"):
|
||||||
|
end_index = json_string.find("``", start_index + len("```json"))
|
||||||
|
extracted_content = json_string[start_index + len("```json"):end_index].strip()
|
||||||
|
|
||||||
# Parse the JSON string into a Python dictionary
|
# Parse the JSON string into a Python dictionary
|
||||||
parsed = json.loads(extracted_content)
|
parsed = json.loads(extracted_content)
|
||||||
elif json_string.startswith("{"):
|
elif json_string.startswith("{"):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user