[GH-ISSUE #7625] Embedded struct in ToolFunction #51377

Open
opened 2026-04-28 19:44:40 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @NatoBoram on GitHub (Nov 12, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7625

What is the issue?

65973ceb64/api/types.go (L165-L177)

This makes creating tools really annoying.

package main

import (
	ollama "github.com/ollama/ollama/api"
)

var modFunctions = []ollama.Tool{{
	Type: "function",
	Function: ollama.ToolFunction{
		Name:        "remove",
		Description: "Remove a post when it violates a rule",
		Parameters: struct {
			Type       string   `json:"type"`
			Required   []string `json:"required"`
			Properties map[string]struct {
				Type        string   `json:"type"`
				Description string   `json:"description"`
				Enum        []string `json:"enum,omitempty"`
			} `json:"properties"`
		}{
			Type:     "object",
			Required: []string{"reason"},
			Properties: map[string]struct {
				Type        string   `json:"type"`
				Description string   `json:"description"`
				Enum        []string `json:"enum,omitempty"`
			}{
				"reason": {
					Type:        "string",
					Description: "These are the rules of the subreddit. If the post violates one of these rules, remove it.",
					Enum: []string{
						"actual_animal_attack",
						"bad_explanatory_comment",
						"direct_link_to_other_subreddit",
						"does_not_fit_the_subreddit",
						"leopard_in_title_or_explanatory_comment",
						"no_explanatory_comment",
						"uncivil_behaviour",
					},
				},
			},
		},
	},
}, {
	Type: "function",
	Function: ollama.ToolFunction{
		Name:        "approve",
		Description: "Approve a post when the explanatory comment explains how someone is suffering consequences from something they voted for, supported or wanted to impose on other people",
		Parameters: struct {
			Type       string   `json:"type"`
			Required   []string `json:"required"`
			Properties map[string]struct {
				Type        string   `json:"type"`
				Description string   `json:"description"`
				Enum        []string `json:"enum,omitempty"`
			} `json:"properties"`
		}{
			Type:     "object",
			Required: []string{"someone", "something", "consequences"},
			Properties: map[string]struct {
				Type        string   `json:"type"`
				Description string   `json:"description"`
				Enum        []string `json:"enum,omitempty"`
			}{
				"someone": {
					Type:        "string",
					Description: "The name of the person who voted for, supported or wanted to impose something on other people.",
				},
				"something": {
					Type:        "string",
					Description: "The thing that the person voted for, supported or wanted to impose on other people.",
				},
				"consequences": {
					Type:        "string",
					Description: "The consequences of the thing that the person voted for, supported or wanted to impose on other people.",
				},
			},
		},
	},
}}

Please make a separate struct for parameters and properties :(

OS

Linux

GPU

Nvidia, AMD

CPU

Intel, AMD

Ollama version

Docker

Originally created by @NatoBoram on GitHub (Nov 12, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7625 ### What is the issue? https://github.com/ollama/ollama/blob/65973ceb6417c2e2796fa59bd3225bc7bd79b403/api/types.go#L165-L177 This makes creating tools really annoying. ```go package main import ( ollama "github.com/ollama/ollama/api" ) var modFunctions = []ollama.Tool{{ Type: "function", Function: ollama.ToolFunction{ Name: "remove", Description: "Remove a post when it violates a rule", Parameters: struct { Type string `json:"type"` Required []string `json:"required"` Properties map[string]struct { Type string `json:"type"` Description string `json:"description"` Enum []string `json:"enum,omitempty"` } `json:"properties"` }{ Type: "object", Required: []string{"reason"}, Properties: map[string]struct { Type string `json:"type"` Description string `json:"description"` Enum []string `json:"enum,omitempty"` }{ "reason": { Type: "string", Description: "These are the rules of the subreddit. If the post violates one of these rules, remove it.", Enum: []string{ "actual_animal_attack", "bad_explanatory_comment", "direct_link_to_other_subreddit", "does_not_fit_the_subreddit", "leopard_in_title_or_explanatory_comment", "no_explanatory_comment", "uncivil_behaviour", }, }, }, }, }, }, { Type: "function", Function: ollama.ToolFunction{ Name: "approve", Description: "Approve a post when the explanatory comment explains how someone is suffering consequences from something they voted for, supported or wanted to impose on other people", Parameters: struct { Type string `json:"type"` Required []string `json:"required"` Properties map[string]struct { Type string `json:"type"` Description string `json:"description"` Enum []string `json:"enum,omitempty"` } `json:"properties"` }{ Type: "object", Required: []string{"someone", "something", "consequences"}, Properties: map[string]struct { Type string `json:"type"` Description string `json:"description"` Enum []string `json:"enum,omitempty"` }{ "someone": { Type: "string", Description: "The name of the person who voted for, supported or wanted to impose something on other people.", }, "something": { Type: "string", Description: "The thing that the person voted for, supported or wanted to impose on other people.", }, "consequences": { Type: "string", Description: "The consequences of the thing that the person voted for, supported or wanted to impose on other people.", }, }, }, }, }} ``` Please make a separate struct for parameters and properties :( ### OS Linux ### GPU Nvidia, AMD ### CPU Intel, AMD ### Ollama version Docker
GiteaMirror added the bug label 2026-04-28 19:44:41 -05:00
Author
Owner

@acidghost commented on GitHub (May 24, 2025):

As a workaround you can refactor the embedded struct in a type declaration and Go won't complain.

<!-- gh-comment-id:2906905938 --> @acidghost commented on GitHub (May 24, 2025): As a workaround you can refactor the embedded struct in a `type` declaration and Go won't complain.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#51377