Class: Ollama::Tool::Function

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

Overview

A class that represents a function definition for tool usage in Ollama API interactions.

This class encapsulates the structure required for defining functions that can be passed to models to enable function calling capabilities. It includes the function's name, description, parameters specification, and list of required parameters.

Examples:

Creating a function definition for a tool

function = Ollama::Tool::Function.new(
  name: 'get_current_weather',
  description: 'Get the current weather for a location',
  parameters: parameters,
  required: %w[location]
)

Defined Under Namespace

Classes: Parameters

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(name:, description:, parameters: nil, required: nil) ⇒ Function

The initialize method sets up a new Tool::Function instance with the specified attributes.

Parameters:

  • name (String)

    the name of the function

  • description (String)

    a brief description of what the function does

  • parameters (Hash, nil) (defaults to: nil)

    optional parameters specification for the function

  • required (Array<String>, nil) (defaults to: nil)

    optional array of required parameter names



49
50
51
52
53
# File 'lib/ollama/tool/function.rb', line 49

def initialize(name:, description:, parameters: nil, required: nil)
  @name, @description, @parameters, @required =
    name, description, (Hash(parameters) if parameters),
    (Array(required) if required)
end

Instance Attribute Details

#descriptionString (readonly)

The description attribute reader returns the description associated with the object.

Returns:

  • (String)

    the description value stored in the instance variable



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

def description
  @description
end

#nameString (readonly)

The name attribute reader returns the name associated with the object.

Returns:

  • (String)

    the name value stored in the instance variable



22
23
24
# File 'lib/ollama/tool/function.rb', line 22

def name
  @name
end

#parametersHash? (readonly)

The parameters attribute reader returns the parameters associated with the object.

Returns:

  • (Hash, nil)

    the parameters hash, or nil if not set



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

def parameters
  @parameters
end

#requiredArray<String>? (readonly)

The required attribute reader returns the required parameter values associated with the object.

Returns:

  • (Array<String>, nil)

    an array of required parameter names, or nil if not set



40
41
42
# File 'lib/ollama/tool/function.rb', line 40

def required
  @required
end