Unverified Commit 5ca88a4f authored by John Wang's avatar John Wang Committed by GitHub

fix: raw json parse in llm router chain (#254)

parent a1c6cecf
......@@ -84,6 +84,7 @@ class RouterOutputParser(BaseOutputParser[Dict[str, str]]):
def parse_json_markdown(self, json_string: str) -> dict:
# Remove the triple backticks if present
json_string = json_string.strip()
start_index = json_string.find("```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
parsed = json.loads(extracted_content)
elif json_string.startswith("{"):
# Parse the JSON string into a Python dictionary
parsed = json.loads(json_string)
else:
raise Exception("Could not find JSON block in the output.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment