[PR #9434] [MERGED] types: allow tool function parameters with either a single type or an array of types #38834

Closed
opened 2026-04-22 23:29:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/9434
Author: @rozgo
Created: 3/1/2025
Status: Merged
Merged: 4/7/2025
Merged by: @ParthSareen

Base: mainHead: bug/tool-prop-type


📝 Commits (3)

  • 734531d support tool prop type to be string or array
  • 1804df1 Merge branch 'main' into bug/tool-prop-type
  • ea32c91 fixes errors in CI, because of tests using string instead of PropertyType

📊 Changes

4 files changed (+149 additions, -27 deletions)

View changed files

📝 api/types.go (+45 -3)
📝 api/types_test.go (+80 -0)
📝 openai/openai_test.go (+8 -8)
📝 server/routes_generate_test.go (+16 -16)

📄 Description

  1. Identified the issue in the api/types.go file where the Type field in the tool function parameters properties was defined as a string, but the API was receiving an array. (For example, in Rust Option<String> is ["string", "null"])

  2. Created a new PropertyType type that can handle both a single string and an array of strings:

    • Added UnmarshalJSON method to handle both string and array inputs
    • Added MarshalJSON method to serialize back to the appropriate format (string for single values, array for multiple)
    • Added String method for string representation
  3. Updated the ToolFunction struct to use the new PropertyType instead of a simple string.

  4. Added tests to ensure the new type works correctly with both string and array inputs.

  5. Verified that all tests pass and the project builds successfully.

This change allows the API to handle tool function parameters with either a single type (like "string") or multiple types (like ["string", "null"]), which is a common pattern in JSON Schema.

Should solve this issue: https://github.com/ollama/ollama/issues/5990


🔄 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/ollama/ollama/pull/9434 **Author:** [@rozgo](https://github.com/rozgo) **Created:** 3/1/2025 **Status:** ✅ Merged **Merged:** 4/7/2025 **Merged by:** [@ParthSareen](https://github.com/ParthSareen) **Base:** `main` ← **Head:** `bug/tool-prop-type` --- ### 📝 Commits (3) - [`734531d`](https://github.com/ollama/ollama/commit/734531d95dbed19778ace2aee4fefc887f7c1d33) support tool prop type to be string or array - [`1804df1`](https://github.com/ollama/ollama/commit/1804df100e3ac5fdf8a4d665af722166d4fa0573) Merge branch 'main' into bug/tool-prop-type - [`ea32c91`](https://github.com/ollama/ollama/commit/ea32c913b2ece53e32723d157e67c92d3c25474d) fixes errors in CI, because of tests using string instead of PropertyType ### 📊 Changes **4 files changed** (+149 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `api/types.go` (+45 -3) 📝 `api/types_test.go` (+80 -0) 📝 `openai/openai_test.go` (+8 -8) 📝 `server/routes_generate_test.go` (+16 -16) </details> ### 📄 Description 1. Identified the issue in the `api/types.go` file where the `Type` field in the tool function parameters properties was defined as a string, but the API was receiving an array. (For example, in Rust `Option<String>` is `["string", "null"]`) 2. Created a new `PropertyType` type that can handle both a single string and an array of strings: - Added `UnmarshalJSON` method to handle both string and array inputs - Added `MarshalJSON` method to serialize back to the appropriate format (string for single values, array for multiple) - Added `String` method for string representation 3. Updated the `ToolFunction` struct to use the new `PropertyType` instead of a simple string. 4. Added tests to ensure the new type works correctly with both string and array inputs. 5. Verified that all tests pass and the project builds successfully. This change allows the API to handle tool function parameters with either a single type (like `"string"`) or multiple types (like `["string", "null"]`), which is a common pattern in JSON Schema. Should solve this issue: https://github.com/ollama/ollama/issues/5990 --- <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-22 23:29:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#38834