From 260137fc122295b1fc9371f460db319ea5e3d07a Mon Sep 17 00:00:00 2001 From: EntropyYue Date: Fri, 18 Jul 2025 06:11:53 +0800 Subject: [PATCH] fix: ollama tool call --- backend/open_webui/utils/response.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/utils/response.py b/backend/open_webui/utils/response.py index 8ddd502e2e..2a54b9af62 100644 --- a/backend/open_webui/utils/response.py +++ b/backend/open_webui/utils/response.py @@ -6,18 +6,17 @@ from open_webui.utils.misc import ( ) -def convert_ollama_tool_call_to_openai(tool_calls: dict) -> dict: +def convert_ollama_tool_call_to_openai(tool_calls: list) -> list: openai_tool_calls = [] for tool_call in tool_calls: + function = tool_call.get("function", {}) openai_tool_call = { - "index": tool_call.get("index", 0), + "index": tool_call.get("index", function.get("index", 0)), "id": tool_call.get("id", f"call_{str(uuid4())}"), "type": "function", "function": { - "name": tool_call.get("function", {}).get("name", ""), - "arguments": json.dumps( - tool_call.get("function", {}).get("arguments", {}) - ), + "name": function.get("name", ""), + "arguments": json.dumps(function.get("arguments", {})), }, } openai_tool_calls.append(openai_tool_call)