Merge pull request #4203 from pipecat-ai/mb/fix-json-decode-tool-calls
Handle incomplete function call arguments from interrupted LLM streams
This commit is contained in:
1
changelog/4203.fixed.md
Normal file
1
changelog/4203.fixed.md
Normal file
@@ -0,0 +1 @@
|
||||
- Fixed a crash (`JSONDecodeError`) when a user interruption occurs while the LLM is streaming function call arguments. Previously, the incomplete JSON arguments were passed directly to `json.loads()`, causing an unhandled exception. Affected services: OpenAI, Google (OpenAI-compatible), and SambaNova.
|
||||
@@ -199,7 +199,11 @@ class GoogleLLMOpenAIBetaService(OpenAILLMService):
|
||||
# which currently results in an empty function name('').
|
||||
continue
|
||||
|
||||
arguments = json.loads(arguments)
|
||||
try:
|
||||
arguments = json.loads(arguments)
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"{self}: Failed to parse function call arguments: {arguments}")
|
||||
continue
|
||||
|
||||
function_calls.append(
|
||||
FunctionCallFromLLM(
|
||||
|
||||
@@ -567,7 +567,11 @@ class BaseOpenAILLMService(LLMService):
|
||||
for function_name, arguments, tool_id in zip(
|
||||
functions_list, arguments_list, tool_id_list
|
||||
):
|
||||
arguments = json.loads(arguments)
|
||||
try:
|
||||
arguments = json.loads(arguments)
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"{self}: Failed to parse function call arguments: {arguments}")
|
||||
continue
|
||||
function_calls.append(
|
||||
FunctionCallFromLLM(
|
||||
context=context,
|
||||
|
||||
@@ -245,7 +245,11 @@ class SambaNovaLLMService(OpenAILLMService): # type: ignore
|
||||
if len(arguments) < 1:
|
||||
continue
|
||||
|
||||
arguments = json.loads(arguments)
|
||||
try:
|
||||
arguments = json.loads(arguments)
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"{self}: Failed to parse function call arguments: {arguments}")
|
||||
continue
|
||||
function_calls.append(
|
||||
FunctionCallFromLLM(
|
||||
context=context,
|
||||
|
||||
Reference in New Issue
Block a user