浏览代码

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

tags/0.3.2
John Wang 2 年前
父节点
当前提交
5ca88a4fd9
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4
    0
      api/core/chain/llm_router_chain.py

+ 4
- 0
api/core/chain/llm_router_chain.py 查看文件

@@ -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.")


正在加载...
取消
保存