Class: OllamaChat::Tools::CVE
- Inherits:
-
Object
- Object
- OllamaChat::Tools::CVE
- Includes:
- Ollama
- Defined in:
- lib/ollama_chat/tools/cve.rb
Overview
A tool for fetching CVE (Common Vulnerabilities and Exposures) information.
This tool allows the chat client to retrieve CVE details by ID from a configured API endpoint. It integrates with the Ollama tool calling system to provide security-related 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 CVE lookup operation.
-
#initialize ⇒ OllamaChat::Tools::CVE
constructor
Initializes a new CVE tool instance.
-
#to_hash ⇒ Hash
Converts the tool to a hash representation.
-
#tool ⇒ Ollama::Tool
Creates and returns a tool definition for getting CVE information.
Constructor Details
#initialize ⇒ OllamaChat::Tools::CVE
Initializes a new CVE tool instance.
18 19 20 |
# File 'lib/ollama_chat/tools/cve.rb', line 18 def initialize @name = 'get_cve' end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the tool.
25 26 27 |
# File 'lib/ollama_chat/tools/cve.rb', line 25 def name @name end |
Instance Method Details
#execute(tool_call, **opts) ⇒ Hash, String
Executes the CVE lookup operation.
This method fetches CVE data from the configured API endpoint using the provided CVE ID. 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 |
# File 'lib/ollama_chat/tools/cve.rb', line 65 def execute(tool_call, **opts) config = opts[:config] cve_id = tool_call.function.arguments.cve_id url = config.tools.get_cve.url % { cve_id: } OllamaChat::Utils::Fetcher.get( url, headers: { 'Accept' => 'application/json', }, debug: OllamaChat::EnvConfig::OLLAMA::CHAT::DEBUG ) do |tmp| data = JSON.parse(tmp.read, object_class: JSON::GenericObject) return data end rescue StandardError => e "Failed to fetch CVE for #{cve_id} #{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.
89 90 91 |
# File 'lib/ollama_chat/tools/cve.rb', line 89 def to_hash tool.to_hash end |
#tool ⇒ Ollama::Tool
Creates and returns a tool definition for getting CVE information.
This method constructs the function signature that describes what the tool does, its parameters, and required fields. The tool expects a CVE-ID 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/cve.rb', line 34 def tool Tool.new( type: 'function', function: Tool::Function.new( name:, description: 'Get the CVE for id as JSON', parameters: Tool::Function::Parameters.new( type: 'object', properties: { cve_id: Tool::Function::Parameters::Property.new( type: 'string', description: 'The CVE-ID to get' ), }, required: %w[cve_id] ) ) ) end |