From 805cce812226a2a5f9902f83c09d6a392d178cd7 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 3 Nov 2026 19:28:22 +0100 Subject: [PATCH] fix: chat stops working with Ollama after a tool call with broken arguments A tool call whose arguments were cut off, rejected before it ran or sent empty made every later message with an Ollama model fail, so the chat stayed stuck until that message was edited or removed. Such calls are now sent to Ollama with empty arguments and the conversation continues. Fixes #33671 --- backend/open_webui/utils/payload.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/payload.py b/backend/open_webui/utils/payload.py index f1befc53a8..962c98696f 100644 --- a/backend/open_webui/utils/payload.py +++ b/backend/open_webui/utils/payload.py @@ -328,12 +328,19 @@ def convert_chat_completions_messages_to_ollama(messages: list[dict]) -> list[di # If tool calls are present, add them to the message ollama_tool_calls = [] for tool_call in tool_calls: + arguments = tool_call.get('function', {}).get('arguments') + if isinstance(arguments, str): + try: + arguments = JSONCodec.loads(arguments) + except JSONCodec.JSONDecodeError: + arguments = {} + ollama_tool_call = { 'index': tool_call.get('index', 0), 'id': tool_call.get('id', None), 'function': { 'name': tool_call.get('function', {}).get('name', ''), - 'arguments': JSONCodec.loads(tool_call.get('function', {}).get('arguments', {})), + 'arguments': arguments if isinstance(arguments, dict) else {}, }, } ollama_tool_calls.append(ollama_tool_call)