mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 04:15:52 +08:00
fix: raw json parse in llm router chain (#254)
This commit is contained in:
parent
a1c6cecf10
commit
5ca88a4fd9
@ -84,6 +84,7 @@ class RouterOutputParser(BaseOutputParser[Dict[str, str]]):
|
|||||||
|
|
||||||
def parse_json_markdown(self, json_string: str) -> dict:
|
def parse_json_markdown(self, json_string: str) -> dict:
|
||||||
# Remove the triple backticks if present
|
# Remove the triple backticks if present
|
||||||
|
json_string = json_string.strip()
|
||||||
start_index = json_string.find("```json")
|
start_index = json_string.find("```json")
|
||||||
end_index = json_string.find("```", start_index + len("```json"))
|
end_index = json_string.find("```", start_index + len("```json"))
|
||||||
|
|
||||||
@ -92,6 +93,9 @@ class RouterOutputParser(BaseOutputParser[Dict[str, str]]):
|
|||||||
|
|
||||||
# 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("{"):
|
||||||
|
# Parse the JSON string into a Python dictionary
|
||||||
|
parsed = json.loads(json_string)
|
||||||
else:
|
else:
|
||||||
raise Exception("Could not find JSON block in the output.")
|
raise Exception("Could not find JSON block in the output.")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user