From f4e99c80f6225f371c2f012d28632deecf8afea4 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 16 Feb 2026 00:53:01 -0600 Subject: [PATCH] refac: "tool_calls" finish reason support --- backend/open_webui/utils/misc.py | 2 +- backend/open_webui/utils/response.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/misc.py b/backend/open_webui/utils/misc.py index 13539ca9d0..a63d425ff5 100644 --- a/backend/open_webui/utils/misc.py +++ b/backend/open_webui/utils/misc.py @@ -447,7 +447,7 @@ def openai_chat_completion_message_template( **({"tool_calls": tool_calls} if tool_calls else {}), } - template["choices"][0]["finish_reason"] = "stop" + template["choices"][0]["finish_reason"] = "tool_calls" if tool_calls else "stop" if usage: template["usage"] = usage diff --git a/backend/open_webui/utils/response.py b/backend/open_webui/utils/response.py index 9d1920651e..5a4028f11b 100644 --- a/backend/open_webui/utils/response.py +++ b/backend/open_webui/utils/response.py @@ -166,6 +166,9 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response) model, message_content, reasoning_content, openai_tool_calls, usage ) + if done and openai_tool_calls: + data["choices"][0]["finish_reason"] = "tool_calls" + line = f"data: {json.dumps(data)}\n\n" yield line