[PR #24827] [CLOSED] fix: handle decoded Ollama tool call arguments #131542

Closed
opened 2026-05-21 17:10:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/24827
Author: @pragnyanramtha
Created: 5/17/2026
Status: Closed

Base: devHead: codex/ollama-tool-call-arguments-v2


📝 Commits (2)

  • 106f919 Handle decoded Ollama tool call arguments
  • 95704ef test: cover Ollama tools forwarding

📊 Changes

2 files changed (+107 additions, -2 deletions)

View changed files

backend/open_webui/test/utils/test_payload.py (+97 -0)
📝 backend/open_webui/utils/payload.py (+10 -2)

📄 Description

Summary

  • Handle OpenAI tool-call arguments that are already decoded or omitted when converting chat messages to Ollama format.
  • Keep root-level OpenAI tools forwarded through the full OpenAI-to-Ollama payload conversion path, with regression coverage for the native tool-calling shape from #23907.
  • Add focused payload conversion tests for JSON-string, decoded-dict, missing tool-call arguments, and tool array forwarding.

Relates to #23907.

Why

Some OpenAI-compatible chat/tool flows can produce function.arguments as an object or omit it. The Ollama conversion path previously called json.loads unconditionally, which raised before the request could be sent.

The full payload regression also covers the native Ollama tool-calling boundary so a resolved tools: [...] array remains present when Open WebUI converts an OpenAI-style chat payload for /api/chat.

Changelog Entry

Description

  • Fix Ollama payload conversion for assistant tool calls whose arguments are already decoded or missing.
  • Add regression coverage for forwarding the OpenAI tools array to Ollama payloads.

Added

  • Unit coverage for tool-call argument conversion in convert_messages_openai_to_ollama.
  • Unit coverage for convert_payload_openai_to_ollama preserving native tool definitions.

Changed

  • None.

Deprecated

  • None.

Removed

  • None.

Fixed

  • Prevent json.loads from raising when tool-call arguments are already a dictionary or are omitted.
  • Guard against regressions where native tool definitions are dropped before reaching Ollama.

Security

  • None.

Breaking Changes

  • None.

Additional Information

Validation:

  • python3 -m py_compile backend/open_webui/utils/payload.py backend/open_webui/test/utils/test_payload.py
  • git diff --check upstream/dev...HEAD
  • TMPDIR=/tmp PYTHONPATH=$PWD/backend uv run --no-project --python 3.12 --with pytest --with python-mimeparse --with Markdown --with beautifulsoup4 --with cryptography --with-requirements backend/requirements-min.txt pytest backend/open_webui/test/utils/test_payload.py -q -> 4 passed
  • TMPDIR=/tmp uv run --no-project --python 3.12 --with 'ruff>=0.15.5' ruff format --check backend/open_webui/utils/payload.py backend/open_webui/test/utils/test_payload.py
  • TMPDIR=/tmp uv run --no-project --python 3.12 --with 'ruff>=0.15.5' ruff check backend/open_webui/test/utils/test_payload.py

Screenshots or Videos

  • Not applicable; backend payload conversion change.

Contributor License Agreement


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/24827 **Author:** [@pragnyanramtha](https://github.com/pragnyanramtha) **Created:** 5/17/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `codex/ollama-tool-call-arguments-v2` --- ### 📝 Commits (2) - [`106f919`](https://github.com/open-webui/open-webui/commit/106f91925f67db2effbb73ab626dc12fb7245272) Handle decoded Ollama tool call arguments - [`95704ef`](https://github.com/open-webui/open-webui/commit/95704efcc2d3456cc80cfa4f64b06437c84b2955) test: cover Ollama tools forwarding ### 📊 Changes **2 files changed** (+107 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `backend/open_webui/test/utils/test_payload.py` (+97 -0) 📝 `backend/open_webui/utils/payload.py` (+10 -2) </details> ### 📄 Description ## Summary - Handle OpenAI tool-call arguments that are already decoded or omitted when converting chat messages to Ollama format. - Keep root-level OpenAI `tools` forwarded through the full OpenAI-to-Ollama payload conversion path, with regression coverage for the native tool-calling shape from #23907. - Add focused payload conversion tests for JSON-string, decoded-dict, missing tool-call arguments, and tool array forwarding. Relates to #23907. ## Why Some OpenAI-compatible chat/tool flows can produce `function.arguments` as an object or omit it. The Ollama conversion path previously called `json.loads` unconditionally, which raised before the request could be sent. The full payload regression also covers the native Ollama tool-calling boundary so a resolved `tools: [...]` array remains present when Open WebUI converts an OpenAI-style chat payload for `/api/chat`. # Changelog Entry ### Description - Fix Ollama payload conversion for assistant tool calls whose arguments are already decoded or missing. - Add regression coverage for forwarding the OpenAI `tools` array to Ollama payloads. ### Added - Unit coverage for tool-call argument conversion in `convert_messages_openai_to_ollama`. - Unit coverage for `convert_payload_openai_to_ollama` preserving native tool definitions. ### Changed - None. ### Deprecated - None. ### Removed - None. ### Fixed - Prevent `json.loads` from raising when tool-call arguments are already a dictionary or are omitted. - Guard against regressions where native tool definitions are dropped before reaching Ollama. ### Security - None. ### Breaking Changes - None. --- ### Additional Information Validation: - `python3 -m py_compile backend/open_webui/utils/payload.py backend/open_webui/test/utils/test_payload.py` - `git diff --check upstream/dev...HEAD` - `TMPDIR=/tmp PYTHONPATH=$PWD/backend uv run --no-project --python 3.12 --with pytest --with python-mimeparse --with Markdown --with beautifulsoup4 --with cryptography --with-requirements backend/requirements-min.txt pytest backend/open_webui/test/utils/test_payload.py -q` -> `4 passed` - `TMPDIR=/tmp uv run --no-project --python 3.12 --with 'ruff>=0.15.5' ruff format --check backend/open_webui/utils/payload.py backend/open_webui/test/utils/test_payload.py` - `TMPDIR=/tmp uv run --no-project --python 3.12 --with 'ruff>=0.15.5' ruff check backend/open_webui/test/utils/test_payload.py` ### Screenshots or Videos - Not applicable; backend payload conversion change. ### Contributor License Agreement - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-21 17:10:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#131542