[PR #7021] [CLOSED] feat: Added native_tool_call model option which enables tool use through API calls #22000

Closed
opened 2026-04-20 03:52:04 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/7021
Author: @smonux
Created: 11/18/2024
Status: Closed

Base: devHead: dev


📝 Commits (10+)

  • bfc5f6b feat: Add tool handling and response modification for non-streaming responses
  • 2a51781 feat: Complete handle_nonstreaming_response with tool call handling
  • 6bcfdaa fix: resolve undefined names 'call_next' and 'response' in handle_nonstreaming_response
  • 83191db refactor: remove unused imports in main.py
  • c17c9e2 fix: correct variable name in nonstreaming response handler
  • eb1366b fix for streaming
  • 6777210 incremental fixes nonstreaming
  • c19c7b5 fix: Non streaming response is working
  • 712f82e fix: now streaming works
  • 0a902fc refac

📊 Changes

57 files changed (+571 additions, -53 deletions)

View changed files

📝 backend/open_webui/apps/ollama/main.py (+2 -0)
📝 backend/open_webui/apps/openai/main.py (+4 -0)
📝 backend/open_webui/main.py (+455 -51)
📝 backend/open_webui/static/assets/pdf-style.css (+2 -2)
📝 backend/open_webui/utils/payload.py (+2 -0)
📝 backend/open_webui/utils/tools.py (+13 -0)
📝 src/lib/components/chat/Chat.svelte (+13 -0)
📝 src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte (+29 -0)
📝 src/lib/components/chat/Settings/General.svelte (+3 -0)
📝 src/lib/i18n/locales/ar-BH/translation.json (+1 -0)
📝 src/lib/i18n/locales/bg-BG/translation.json (+1 -0)
📝 src/lib/i18n/locales/bn-BD/translation.json (+1 -0)
📝 src/lib/i18n/locales/ca-ES/translation.json (+1 -0)
📝 src/lib/i18n/locales/ceb-PH/translation.json (+1 -0)
📝 src/lib/i18n/locales/cs-CZ/translation.json (+1 -0)
📝 src/lib/i18n/locales/da-DK/translation.json (+1 -0)
📝 src/lib/i18n/locales/de-DE/translation.json (+1 -0)
📝 src/lib/i18n/locales/dg-DG/translation.json (+1 -0)
📝 src/lib/i18n/locales/el-GR/translation.json (+1 -0)
📝 src/lib/i18n/locales/en-GB/translation.json (+1 -0)

...and 37 more files

📄 Description

A new parameter model called "native_tool_call" is added.

If false (the default), the behaviour when there are tools enabled doesn't change: a prompt is built which asks the model to generate a function call compatible with the offered tools. If it's valid the ouput is the added to the context.

If true, the native mechanism that the API has is used instead. That means that the responses have to be inspected to detect if a tool_call has to be handled and act accordingly. This allows more complex behaviours where the model can try several strategies and call tools knowing the output of others.

Ollama tool calling API only supports non streaming requests. In case both streaming and native_tool call are present, native tool calling is silently ignored.
Testing

The feature has been tested through the ui and using a script which calls these endpoints using
/api/chat/completions
/ollama/api/chat

With the OpenAI API, these models have been tested, with varying success

OK
gpt-4o-mini
qwen/qwen-2.5-72b-instruct (OpenRouter endpoint)
anthropic/claude-3-haiku (OpenRouter endpoint)
deepseek/deepseek-chat (OpenRouter endpoint)
google/gemini-pro (OpenRouter endpoint)
Partial support
cohere/command-r-plus (OpenRouter endpoint)

-Fails
meta-llama/llama-3.1-70b-instruct (OpenRouter endpoint)

With the Ollama API, only llama3.2:3b has been tested.

These are prompts used with two functions provided:

get_current_time
get_sensor_data with a single argument which just returns the sensorid multiplied by two.
("what is the first letter of the latin alphabet",  "no tools needed"),
("what is the date of today (use the get_current_time function)", " 1 tool no args"),
("what is the value of sensor 1", " 1 tool with args"),
("what are the value of sensors 1 and 4", " 2 tools (the may be run in parallel if the API supports it )"),
("if the value of sensors 1 is less that 5 m/s report the value of sensor 4. Otherwise report sensor 3", " 2 tools (in s
equence if the model does it )"),


("choose a integer between 1 an 10 write it here. If it's bigger that 5 report sensor 4. Otherwise report sensor 1", " tool call after having generated some text"),
("what is the value of sensor 'HELLO' ",  "tool call raises an exception")

The full output is attached to the PR.output.txt

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • [-] Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
    Will update docs if gets accepted.
  • Dependencies: Are there any new dependencies? NO
  • Testing: Have you written and run sufficient tests for validating the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • [X ] Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:

Changelog Entry

Description

A new parameter model called "native_tool_call" is added. If set to true, the tool calls are performed using the API and instead of the prompt based approach which is the default.


🔄 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/7021 **Author:** [@smonux](https://github.com/smonux) **Created:** 11/18/2024 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `dev` --- ### 📝 Commits (10+) - [`bfc5f6b`](https://github.com/open-webui/open-webui/commit/bfc5f6b2f642ce5d6c25dd26802677b921661bc3) feat: Add tool handling and response modification for non-streaming responses - [`2a51781`](https://github.com/open-webui/open-webui/commit/2a51781633fa5e0ce696597c2e24513e4fc71332) feat: Complete handle_nonstreaming_response with tool call handling - [`6bcfdaa`](https://github.com/open-webui/open-webui/commit/6bcfdaaaf0329be9636c8b58a3966b751569b13e) fix: resolve undefined names 'call_next' and 'response' in handle_nonstreaming_response - [`83191db`](https://github.com/open-webui/open-webui/commit/83191dbe087341ff90a18bf0eab2c624996b14c3) refactor: remove unused imports in main.py - [`c17c9e2`](https://github.com/open-webui/open-webui/commit/c17c9e2558c266ee5761976b1583ae437948cb3d) fix: correct variable name in nonstreaming response handler - [`eb1366b`](https://github.com/open-webui/open-webui/commit/eb1366b4bcb9730a954030e6c2b5303f7ce9b790) fix for streaming - [`6777210`](https://github.com/open-webui/open-webui/commit/6777210d1f8eb3dd40c2c9c0bca8157a22a35a64) incremental fixes nonstreaming - [`c19c7b5`](https://github.com/open-webui/open-webui/commit/c19c7b56cf11586f07955110cbc3550122979d96) fix: Non streaming response is working - [`712f82e`](https://github.com/open-webui/open-webui/commit/712f82e4ddb9f3361fab74dd7e9cc46852ea7175) fix: now streaming works - [`0a902fc`](https://github.com/open-webui/open-webui/commit/0a902fc69185ec349310242cc6cb425df637dcba) refac ### 📊 Changes **57 files changed** (+571 additions, -53 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/apps/ollama/main.py` (+2 -0) 📝 `backend/open_webui/apps/openai/main.py` (+4 -0) 📝 `backend/open_webui/main.py` (+455 -51) 📝 `backend/open_webui/static/assets/pdf-style.css` (+2 -2) 📝 `backend/open_webui/utils/payload.py` (+2 -0) 📝 `backend/open_webui/utils/tools.py` (+13 -0) 📝 `src/lib/components/chat/Chat.svelte` (+13 -0) 📝 `src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte` (+29 -0) 📝 `src/lib/components/chat/Settings/General.svelte` (+3 -0) 📝 `src/lib/i18n/locales/ar-BH/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/bg-BG/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/bn-BD/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/ca-ES/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/ceb-PH/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/cs-CZ/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/da-DK/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/de-DE/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/dg-DG/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/el-GR/translation.json` (+1 -0) 📝 `src/lib/i18n/locales/en-GB/translation.json` (+1 -0) _...and 37 more files_ </details> ### 📄 Description A new parameter model called "native_tool_call" is added. If false (the default), the behaviour when there are tools enabled doesn't change: a prompt is built which asks the model to generate a function call compatible with the offered tools. If it's valid the ouput is the added to the context. If true, the native mechanism that the API has is used instead. That means that the responses have to be inspected to detect if a tool_call has to be handled and act accordingly. This allows more complex behaviours where the model can try several strategies and call tools knowing the output of others. Ollama tool calling API only supports non streaming requests. In case both streaming and native_tool call are present, native tool calling is silently ignored. Testing The feature has been tested through the ui and using a script which calls these endpoints using /api/chat/completions /ollama/api/chat With the OpenAI API, these models have been tested, with varying success OK gpt-4o-mini qwen/qwen-2.5-72b-instruct (OpenRouter endpoint) anthropic/claude-3-haiku (OpenRouter endpoint) deepseek/deepseek-chat (OpenRouter endpoint) google/gemini-pro (OpenRouter endpoint) Partial support cohere/command-r-plus (OpenRouter endpoint) -Fails meta-llama/llama-3.1-70b-instruct (OpenRouter endpoint) With the Ollama API, only llama3.2:3b has been tested. These are prompts used with two functions provided: get_current_time get_sensor_data with a single argument which just returns the sensorid multiplied by two. ``` ("what is the first letter of the latin alphabet", "no tools needed"), ("what is the date of today (use the get_current_time function)", " 1 tool no args"), ("what is the value of sensor 1", " 1 tool with args"), ("what are the value of sensors 1 and 4", " 2 tools (the may be run in parallel if the API supports it )"), ("if the value of sensors 1 is less that 5 m/s report the value of sensor 4. Otherwise report sensor 3", " 2 tools (in s equence if the model does it )"), ("choose a integer between 1 an 10 write it here. If it's bigger that 5 report sensor 4. Otherwise report sensor 1", " tool call after having generated some text"), ("what is the value of sensor 'HELLO' ", "tool call raises an exception") ``` The full output is attached to the PR.[output.txt](https://github.com/user-attachments/files/17806506/output.txt) - [X] **Target branch:** Please verify that the pull request targets the `dev` branch. - [X] **Description:** Provide a concise description of the changes made in this pull request. - [X] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [-] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? Will update docs if gets accepted. - [X] **Dependencies:** Are there any new dependencies? NO - [X] **Testing:** Have you written and run sufficient tests for validating the changes? - [X] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [X ] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following: # Changelog Entry ### Description A new parameter model called "native_tool_call" is added. If set to true, the tool calls are performed using the API and instead of the prompt based approach which is the default. --- <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-04-20 03:52:04 -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#22000