Handle incomplete function call arguments from interrupted LLM streams
When a user interruption causes the LLM chunk stream to exit early, function call arguments may be incomplete JSON. Wrap json.loads() in try/except JSONDecodeError to skip malformed function calls with a warning instead of crashing. Fixes #2461.
This commit is contained in:
@@ -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