Class: OllamaChat::Tools::EndOfLife
- Inherits:
-
Object
- Object
- OllamaChat::Tools::EndOfLife
- Includes:
- Ollama
- Defined in:
- lib/ollama_chat/tools/endoflife.rb
Overview
A tool for fetching endoflife.date product information.
This tool allows the chat client to retrieve endoflife.date information for software products by ID. It integrates with the Ollama tool calling system to provide lifecycle and support information to the language model.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Returns the name of the tool.
Instance Method Summary collapse
-
#execute(tool_call, **opts) ⇒ Hash, String
Executes the endoflife lookup operation.
-
#initialize ⇒ OllamaChat::Tools::EndOfLife
constructor
Initializes a new endoflife tool instance.
-
#to_hash ⇒ Hash
Converts the tool to a hash representation.
-
#tool ⇒ Ollama::Tool
Creates and returns a tool definition for getting endoflife information.
Constructor Details
#initialize ⇒ OllamaChat::Tools::EndOfLife
Initializes a new endoflife tool instance.
18 19 20 |
# File 'lib/ollama_chat/tools/endoflife.rb', line 18 def initialize @name = 'get_endoflife' end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the tool.
25 26 27 |
# File 'lib/ollama_chat/tools/endoflife.rb', line 25 def name @name end |
Instance Method Details
#execute(tool_call, **opts) ⇒ Hash, String
Executes the endoflife lookup operation.
This method fetches endoflife data from the endoflife.date API using the provided product name. It handles the HTTP request, parses the JSON response, and returns the structured data.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ollama_chat/tools/endoflife.rb', line 65 def execute(tool_call, **opts) config = opts[:config] product = tool_call.function.arguments.product # Construct the URL for the endoflife API url = config.tools.get_endoflife.url % { product: } # Fetch the data from endoflife.date API OllamaChat::Utils::Fetcher.get( url, headers: { 'Accept' => 'application/json', 'User-Agent' => OllamaChat::Chat.user_agent }, debug: OllamaChat::EnvConfig::OLLAMA::CHAT::DEBUG ) do |tmp| # Parse the JSON response data = JSON.parse(tmp.read, object_class: JSON::GenericObject) return data end rescue StandardError => e "Failed to fetch endoflife data for #{product}: #{e.class}: #{e.}" 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.
95 96 97 |
# File 'lib/ollama_chat/tools/endoflife.rb', line 95 def to_hash tool.to_hash end |
#tool ⇒ Ollama::Tool
Creates and returns a tool definition for getting endoflife information.
This method constructs the function signature that describes what the tool does, its parameters, and required fields. The tool expects a product name parameter to be provided.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ollama_chat/tools/endoflife.rb', line 34 def tool Tool.new( type: 'function', function: Tool::Function.new( name:, description: 'Get the endoflife information for a product as JSON', parameters: Tool::Function::Parameters.new( type: 'object', properties: { product: Tool::Function::Parameters::Property.new( type: 'string', description: 'The product name to get endoflife information for' ), }, required: %w[product] ) ) ) end |