Module: OllamaChat::Tools
- Defined in:
- lib/ollama_chat/tools.rb
Overview
A module that provides tool registration and management for OllamaChat.
The Tools module serves as a registry for available tools that can be invoked during chat conversations. It maintains a collection of registered tools and provides methods for registering new tools and accessing the complete set of available tools for use in chat interactions.
Defined Under Namespace
Modules: Concern Classes: RunTests
Class Attribute Summary collapse
-
.registered ⇒ Hash
The registered attribute reader.
Class Method Summary collapse
-
.register(tool) ⇒ OllamaChat::Tools
Registers a tool class in the registry.
-
.registered?(register_name) ⇒ TrueClass, FalseClass
Checks if a tool with the given name is registered.
-
.registered_class(name) ⇒ Class
Returns the tool class for a registered tool name.
-
.registered_tool(name, chat:) ⇒ OllamaChat::Tools::Concern?
Instantiates a registered tool, binding it to the given chat session.
Class Attribute Details
.registered ⇒ Hash
The registered attribute reader
15 16 17 |
# File 'lib/ollama_chat/tools.rb', line 15 def registered @registered end |
Class Method Details
.register(tool) ⇒ OllamaChat::Tools
Registers a tool class in the registry.
The class (not an instance) is stored. Instantiation is deferred
to registered_tool(name, chat:) at request time, so each
invocation gets a fresh instance bound to the current session.
66 67 68 69 70 71 72 73 |
# File 'lib/ollama_chat/tools.rb', line 66 def register(tool) name = tool.register_name.to_s name.present? or raise ArgumentError, 'tool needs a name' registered.key?(name) and raise ArgumentError, 'tool %s already registered' % name registered[name] = tool self end |
.registered?(register_name) ⇒ TrueClass, FalseClass
Checks if a tool with the given name is registered.
81 82 83 |
# File 'lib/ollama_chat/tools.rb', line 81 def registered?(register_name) registered.key?(register_name.to_s) end |
.registered_class(name) ⇒ Class
Returns the tool class for a registered tool name.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ollama_chat/tools.rb', line 22 def registered_class(name) name = name.to_s registered.key?(name) or raise ArgumentError, 'tool %s not registered' tool = registered[name] if tool.is_a?(Class) tool else tool.class end end |
.registered_tool(name, chat:) ⇒ OllamaChat::Tools::Concern?
Instantiates a registered tool, binding it to the given chat session.
The registry stores tool classes (not instances). This method
produces a fresh instance with the chat reference injected via
Concern#initialize(chat), making self.chat available for
config access and feedback during execution.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ollama_chat/tools.rb', line 44 def registered_tool(name, chat:) name = name.to_s case tool = registered[name] when NilClass nil when Class tool.new(chat) else tool end end |