Class: Ollama::Tool

Inherits:
Object
  • Object
show all
Includes:
DTO
Defined in:
lib/ollama/tool.rb

Overview

Represents a tool definition used in interactions with the Ollama API. This class encapsulates the structure required for defining tools that can be passed to models to enable function calling capabilities. It includes the type of tool and the associated function definition, which specifies the tool's name, description, parameters, and required fields.

Examples:

Creating a tool with a function definition

tool = Ollama::Tool.new(
  type: 'function',
  function: Ollama::Tool::Function.new(
    name: 'get_current_weather',
    description: 'Get the current weather for a location',
    parameters: Ollama::Tool::Function::Parameters.new(
      type: 'object',
      properties: { location: property },
      required: %w[location]
    )
  )
)

Defined Under Namespace

Classes: Function

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DTO

#==, #as_array, #as_array_of_hashes, #as_hash, #as_json, #empty?, #to_json

Constructor Details

#initialize(type:, function:) ⇒ Tool

The initialize method sets up a new Tool instance with the specified type and function.

associated with the tool

Parameters:

  • type (String)

    the type of tool being created

  • function (Ollama::Tool::Function)

    the function definition



42
43
44
# File 'lib/ollama/tool.rb', line 42

def initialize(type:, function:)
  @type, @function = type, function.to_hash
end

Instance Attribute Details

#functionHash (readonly)

The function attribute reader returns the function definition associated with the tool.

as the function's name, description, parameters, and required fields

Returns:

  • (Hash)

    the function definition as a hash, containing details such



34
35
36
# File 'lib/ollama/tool.rb', line 34

def function
  @function
end

#typeString (readonly)

The type attribute reader returns the type associated with the tool.

calling capabilities

Returns:

  • (String)

    the type of tool, typically 'function' for function



27
28
29
# File 'lib/ollama/tool.rb', line 27

def type
  @type
end