refac
This commit is contained in:
@@ -4163,25 +4163,26 @@ async def streaming_chat_response_handler(response, ctx):
|
|||||||
tool_args = tool_call.get("function", {}).get("arguments", "{}")
|
tool_args = tool_call.get("function", {}).get("arguments", "{}")
|
||||||
|
|
||||||
tool_function_params = {}
|
tool_function_params = {}
|
||||||
try:
|
if tool_args and tool_args.strip():
|
||||||
# json.loads cannot be used because some models do not produce valid JSON
|
|
||||||
tool_function_params = ast.literal_eval(tool_args)
|
|
||||||
except Exception as e:
|
|
||||||
log.debug(e)
|
|
||||||
# Fallback to JSON parsing
|
|
||||||
try:
|
try:
|
||||||
tool_function_params = json.loads(tool_args)
|
# json.loads cannot be used because some models do not produce valid JSON
|
||||||
|
tool_function_params = ast.literal_eval(tool_args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(
|
log.debug(e)
|
||||||
f"Error parsing tool call arguments: {tool_args}"
|
# Fallback to JSON parsing
|
||||||
)
|
try:
|
||||||
results.append(
|
tool_function_params = json.loads(tool_args)
|
||||||
{
|
except Exception as e:
|
||||||
"tool_call_id": tool_call_id,
|
log.error(
|
||||||
"content": f"Error: Tool call arguments could not be parsed. The model generated malformed or incomplete JSON for `{tool_function_name}`. Please try again.",
|
f"Error parsing tool call arguments: {tool_args}"
|
||||||
}
|
)
|
||||||
)
|
results.append(
|
||||||
continue
|
{
|
||||||
|
"tool_call_id": tool_call_id,
|
||||||
|
"content": f"Error: Tool call arguments could not be parsed. The model generated malformed or incomplete JSON for `{tool_function_name}`. Please try again.",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
# Ensure arguments are valid JSON for downstream LLM integrations
|
# Ensure arguments are valid JSON for downstream LLM integrations
|
||||||
log.debug(
|
log.debug(
|
||||||
|
|||||||
Reference in New Issue
Block a user