Class: OllamaChat::Tools::Location
- Inherits:
-
Object
- Object
- OllamaChat::Tools::Location
- 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
-
#name ⇒ String
readonly
Returns the name of the tool.
Instance Method Summary collapse
-
#execute(tool_call, **opts) ⇒ String
Executes the location retrieval operation.
-
#initialize ⇒ OllamaChat::Tools::Location
constructor
Initializes a new get_location tool instance.
-
#to_hash ⇒ Hash
Converts the tool to a hash representation.
-
#tool ⇒ Ollama::Tool
Creates and returns a tool definition for getting location information.
Constructor Details
#initialize ⇒ OllamaChat::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
#name ⇒ String (readonly)
Returns the name of the tool.
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.
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_hash ⇒ Hash
Converts the tool to a hash representation.
This method provides a standardized way to serialize the tool definition for use in tool calling systems.
66 67 68 |
# File 'lib/ollama_chat/tools/location.rb', line 66 def to_hash tool.to_hash end |
#tool ⇒ Ollama::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.
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 |