Class: OllamaChat::Tools::Location

Inherits:
Object
  • Object
show all
Includes:
Ollama
Defined in:
lib/ollama_chat/tools/location.rb

Overview

A tool for retrieving the current location, time, and system of units.

This tool allows the chat client to get the current location information, including time and system of units for the user. It integrates with the Ollama tool calling system to provide contextual location data to the language model.

The tool returns structured JSON data containing location coordinates, time, and unit system information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOllamaChat::Tools::Location

Initializes a new get_location tool instance.



15
16
17
# File 'lib/ollama_chat/tools/location.rb', line 15

def initialize
  @name = 'get_location'
end

Instance Attribute Details

#nameString (readonly)

Returns the name of the tool.

Returns:

  • (String)

    the name of the tool (‘get_location’)



22
23
24
# File 'lib/ollama_chat/tools/location.rb', line 22

def name
  @name
end

Instance Method Details

#execute(tool_call, **opts) ⇒ String

Executes the location retrieval operation.

This method fetches the current location data from the chat instance and returns it as JSON.

Parameters:

  • tool_call (Ollama::Tool::Call)

    the tool call object containing function details

  • opts (Hash)

    additional options

Options Hash (**opts):

Returns:

  • (String)

    the location data as a JSON string

Raises:

  • (StandardError)

    if there’s an issue with location data retrieval or JSON serialization



55
56
57
58
# File 'lib/ollama_chat/tools/location.rb', line 55

def execute(tool_call, **opts)
  chat = opts[:chat]
  chat.location_data.to_json
end

#to_hashHash

Converts the tool to a hash representation.

This method provides a standardized way to serialize the tool definition for use in tool calling systems.

Returns:

  • (Hash)

    a hash representation of the tool



66
67
68
# File 'lib/ollama_chat/tools/location.rb', line 66

def to_hash
  tool.to_hash
end

#toolOllama::Tool

Creates and returns a tool definition for getting location information.

This method constructs the function signature that describes what the tool does, its parameters, and required fields. The tool takes no parameters.

Returns:

  • (Ollama::Tool)

    a tool definition for retrieving location information



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ollama_chat/tools/location.rb', line 30

def tool
  Tool.new(
    type: 'function',
    function: Tool::Function.new(
      name:,
      description: 'Get the current location, time and system of units of the user as JSON',
      parameters: Tool::Function::Parameters.new(
        type: 'object',
        properties: {},
        required: []
      )
    )
  )
end