From 99ce85f20f13168f05fb77db8d1606cea1bec578 Mon Sep 17 00:00:00 2001 From: izumi0004 <46021271+izumi0004@users.noreply.github.com> Date: Sun, 20 Apr 2025 23:25:08 +0800 Subject: [PATCH] fix: handling tool calls in streamed responses --- backend/open_webui/utils/middleware.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 4dde09643..49e0d0a70 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -1671,6 +1671,15 @@ async def process_chat_response( if current_response_tool_call is None: # Add the new tool call + delta_tool_call.setdefault( + "function", {} + ) + delta_tool_call["function"].setdefault( + "name", "" + ) + delta_tool_call["function"].setdefault( + "arguments", "" + ) response_tool_calls.append( delta_tool_call )