Skip to content

Commit

Permalink
community: handle chatdeepinfra jsondecode error (#27603)
Browse files Browse the repository at this point in the history
Fixes #27602 

Added error handling to return empty dict if args is empty string or
None.

Co-authored-by: Erick Friis <[email protected]>
  • Loading branch information
ShawnLJW and efriis authored Nov 7, 2024
1 parent 0588bab commit 6f368e9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libs/community/langchain_community/chat_models/deepinfra.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import logging
from json import JSONDecodeError
from typing import (
Any,
AsyncIterator,
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 6f368e9

Please sign in to comment.