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('').
|
# which currently results in an empty function name('').
|
||||||
continue
|
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(
|
function_calls.append(
|
||||||
FunctionCallFromLLM(
|
FunctionCallFromLLM(
|
||||||
|
|||||||
@@ -567,7 +567,11 @@ class BaseOpenAILLMService(LLMService):
|
|||||||
for function_name, arguments, tool_id in zip(
|
for function_name, arguments, tool_id in zip(
|
||||||
functions_list, arguments_list, tool_id_list
|
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(
|
function_calls.append(
|
||||||
FunctionCallFromLLM(
|
FunctionCallFromLLM(
|
||||||
context=context,
|
context=context,
|
||||||
|
|||||||
@@ -245,7 +245,11 @@ class SambaNovaLLMService(OpenAILLMService): # type: ignore
|
|||||||
if len(arguments) < 1:
|
if len(arguments) < 1:
|
||||||
continue
|
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(
|
function_calls.append(
|
||||||
FunctionCallFromLLM(
|
FunctionCallFromLLM(
|
||||||
context=context,
|
context=context,
|
||||||
|
|||||||
Reference in New Issue
Block a user