Module: OllamaChat::Tools::Concern

Extended by:
Tins::Concern
Includes:
Utils::Backup, Utils::ValueFormatter
Included in:
RunTests
Defined in:
lib/ollama_chat/tools/concern.rb

Overview

A module that provides common functionality for OllamaChat tools.

This module serves as a base class for all tool implementations in the OllamaChat application, providing shared behavior and methods that tools can inherit from. It includes delegation to the tool name and registration functionality to integrate tools into the chat system’s tool registry.

Instance Method Summary collapse

Methods included from Utils::Backup

#perform_backup

Methods included from Utils::ValueFormatter

#format_bytes, #format_tokens

Instance Method Details

#nameString

The name method returns the registered name of the tool.

Returns:

  • (String)

    the registered name of the tool instance



37
38
39
# File 'lib/ollama_chat/tools/concern.rb', line 37

def name
  self.class.register_name
end

#to_hashHash

The to_hash method converts the tool to a hash representation.

Returns:

  • (Hash)

    a hash representation of the tool



60
61
62
# File 'lib/ollama_chat/tools/concern.rb', line 60

def to_hash
  tool.to_hash
end

#valid_json?Proc

The valid_json? method returns a proc that validates JSON data from a temporary file.

Returns:

  • (Proc)

    a proc that takes a temporary file and returns its JSON content or raises an error



46
47
48
49
50
51
52
53
54
55
# File 'lib/ollama_chat/tools/concern.rb', line 46

def valid_json?
  -> tmp {
    if data = tmp.read.full?
      JSON.parse(data)
      return data
    else
      raise JSON::ParserError, 'require JSON data'
    end
  }
end