Module: OllamaChat::Tools::Concern
- Extended by:
- Tins::Concern
- Includes:
- Feedback, Utils::Backup, Utils::Redact, 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.
Constant Summary
Constants included from Feedback
Instance Attribute Summary collapse
-
#chat ⇒ OllamaChat::Chat
readonly
The chat attribute reader.
Instance Method Summary collapse
-
#allowed_paths ⇒ Array<String>
private
Returns the list of allowed filesystem paths for this tool, as configured in the tool's
allowedsetting. -
#initialize(chat) ⇒ Object
Initializes the tool instance with a reference to the chat session.
-
#name ⇒ String
The name method returns the registered name of the tool.
-
#to_hash ⇒ Hash
The to_hash method converts the tool to a hash representation.
-
#tool_config ⇒ ComplexConfig::Settings?
private
Returns the configuration hash for this tool from the application config (
config[:tools][:functions][<name>]). -
#valid_json? ⇒ Proc
private
The valid_json? method returns a proc that validates JSON data from a temporary file.
Methods included from Feedback
Methods included from Utils::Backup
Methods included from Utils::Redact
#redact_password, redact_password
Methods included from Utils::ValueFormatter
Instance Attribute Details
#chat ⇒ OllamaChat::Chat (readonly)
The chat attribute reader.
70 71 72 |
# File 'lib/ollama_chat/tools/concern.rb', line 70 def chat @chat end |
Instance Method Details
#allowed_paths ⇒ Array<String> (private)
Returns the list of allowed filesystem paths for this tool, as configured
in the tool's allowed setting.
Expands each configured path and filters out non-existent entries.
Returns an empty array if the tool has no allowed paths configured.
117 118 119 120 121 122 |
# File 'lib/ollama_chat/tools/concern.rb', line 117 def allowed_paths tool_config&.allowed?.to_a.filter_map { pathname = Pathname.new(_1). pathname.exist?.full? { pathname.to_path } } end |
#initialize(chat) ⇒ Object
Initializes the tool instance with a reference to the chat session.
56 57 58 |
# File 'lib/ollama_chat/tools/concern.rb', line 56 def initialize(chat) @chat = chat end |
#name ⇒ String
The name method returns the registered name of the tool.
63 64 65 |
# File 'lib/ollama_chat/tools/concern.rb', line 63 def name self.class.register_name end |
#to_hash ⇒ Hash
The to_hash method converts the tool to a hash representation.
75 76 77 |
# File 'lib/ollama_chat/tools/concern.rb', line 75 def to_hash tool.to_hash end |
#tool_config ⇒ ComplexConfig::Settings? (private)
Returns the configuration hash for this tool from the application
config (config[:tools][:functions][<name>]).
Used to read tool-specific settings such as allowed: paths,
require_confirmation:, result_display_timeout:, and (for
execute_git) the commands: subcommand map.
106 107 108 |
# File 'lib/ollama_chat/tools/concern.rb', line 106 def tool_config chat.config.tools.functions[name] end |
#valid_json? ⇒ Proc (private)
The valid_json? method returns a proc that validates JSON data from a temporary file.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ollama_chat/tools/concern.rb', line 86 def valid_json? -> tmp { if data = tmp.read.full? JSON.parse(data) return data else raise JSON::ParserError, 'require JSON data' end } end |