Class: Aiko::Tools::Registry
- Inherits:
-
Object
- Object
- Aiko::Tools::Registry
- Defined in:
- lib/aiko/tools/registry.rb
Instance Method Summary collapse
- #dispatch(name, arguments, callbacks:) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(tool) ⇒ Object
- #schemas ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
6 7 8 |
# File 'lib/aiko/tools/registry.rb', line 6 def initialize @tools = {} end |
Instance Method Details
#dispatch(name, arguments, callbacks:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aiko/tools/registry.rb', line 29 def dispatch(name, arguments, callbacks:) tool = @tools[name] return "Error: unknown tool '#{name}'" unless tool if tool.requires_approval?(arguments) && !callbacks.confirm?(tool.(arguments)) return "User declined to run this tool." end begin tool.call(arguments) rescue ToolError, SystemCallError => e "Error: #{e.}" end end |
#register(tool) ⇒ Object
10 11 12 13 14 |
# File 'lib/aiko/tools/registry.rb', line 10 def register(tool) raise ArgumentError, "tool already registered: #{tool.name}" if @tools.key?(tool.name) @tools[tool.name] = tool end |
#schemas ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/aiko/tools/registry.rb', line 16 def schemas @tools.values.map do |tool| { "type" => "function", "function" => { "name" => tool.name, "description" => tool.description, "parameters" => tool.input_schema } } end end |