Class: Botiasloop::Tools::Registry
- Inherits:
-
Object
- Object
- Botiasloop::Tools::Registry
- Defined in:
- lib/botiasloop/tools/registry.rb
Constant Summary collapse
- EMPTY_PARAMETERS_SCHEMA =
{ "type" => "object", "properties" => {}, "required" => [], "additionalProperties" => false, "strict" => true }.freeze
Instance Attribute Summary collapse
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#deregister(name) ⇒ Object
Deregister a tool by name.
-
#execute(name, arguments) ⇒ Hash
Execute a tool by name.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(tool_class, **args) ⇒ Object
Register a tool class.
-
#schemas ⇒ Hash
Generate OpenAI-compatible tool schemas.
-
#tool_classes ⇒ Array<Class>
Array of registered tool classes.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
16 17 18 19 |
# File 'lib/botiasloop/tools/registry.rb', line 16 def initialize @tools = {} @tool_instances = {} end |
Instance Attribute Details
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
6 7 8 |
# File 'lib/botiasloop/tools/registry.rb', line 6 def tools @tools end |
Instance Method Details
#deregister(name) ⇒ Object
Deregister a tool by name
33 34 35 36 |
# File 'lib/botiasloop/tools/registry.rb', line 33 def deregister(name) @tools.delete(name) @tool_instances.delete(name) end |
#execute(name, arguments) ⇒ Hash
Execute a tool by name
58 59 60 61 62 63 64 65 |
# File 'lib/botiasloop/tools/registry.rb', line 58 def execute(name, arguments) tool_class = @tools[name] raise Error, "Unknown tool: #{name}" unless tool_class args = @tool_instances[name] tool = args ? tool_class.new(**args) : tool_class.new tool.execute(**arguments.transform_keys(&:to_sym)) end |
#register(tool_class, **args) ⇒ Object
Register a tool class
25 26 27 28 |
# File 'lib/botiasloop/tools/registry.rb', line 25 def register(tool_class, **args) @tools[tool_class.tool_name] = tool_class @tool_instances[tool_class.tool_name] = args end |
#schemas ⇒ Hash
Generate OpenAI-compatible tool schemas
40 41 42 43 44 45 |
# File 'lib/botiasloop/tools/registry.rb', line 40 def schemas @tools.transform_values do |tool_class| args = @tool_instances[tool_class.tool_name] args ? tool_class.new(**args) : tool_class.new end end |
#tool_classes ⇒ Array<Class>
Returns Array of registered tool classes.
48 49 50 |
# File 'lib/botiasloop/tools/registry.rb', line 48 def tool_classes @tools.values end |