mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-27 21:45:08 +00:00
community: handle chatdeepinfra jsondecode error (#27603)
Fixes #27602 Added error handling to return empty dict if args is empty string or None. Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
parent
0588bab33e
commit
6f368e9eab
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from json import JSONDecodeError
|
||||
from typing import (
|
||||
Any,
|
||||
AsyncIterator,
|
||||
@ -96,7 +97,10 @@ def _parse_tool_calling(tool_call: dict) -> ToolCall:
|
||||
|
||||
"""
|
||||
name = tool_call["function"].get("name", "")
|
||||
args = json.loads(tool_call["function"]["arguments"])
|
||||
try:
|
||||
args = json.loads(tool_call["function"]["arguments"])
|
||||
except (JSONDecodeError, TypeError):
|
||||
args = {}
|
||||
id = tool_call.get("id")
|
||||
return create_tool_call(name=name, args=args, id=id)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user