Class: Async::Ollama::Toolbox
- Inherits:
-
Object
- Object
- Async::Ollama::Toolbox
- Defined in:
- lib/async/ollama/toolbox.rb
Overview
Manages a collection of tools and dispatches calls to them.
Instance Attribute Summary collapse
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#call(message) ⇒ Object
Calls a registered tool with the given message.
- #explain ⇒ Object
-
#initialize ⇒ Toolbox
constructor
Initializes a new, empty toolbox.
-
#register(name, schema, &block) ⇒ Object
Registers a new tool with the given name, schema, and block.
- #The registered tools by name.=(registeredtoolsbyname. = (value)) ⇒ Object
Constructor Details
#initialize ⇒ Toolbox
Initializes a new, empty toolbox.
45 46 47 |
# File 'lib/async/ollama/toolbox.rb', line 45 def initialize @tools = {} end |
Instance Attribute Details
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
50 51 52 |
# File 'lib/async/ollama/toolbox.rb', line 50 def tools @tools end |
Instance Method Details
#call(message) ⇒ Object
Calls a registered tool with the given message.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/async/ollama/toolbox.rb', line 63 def call() function = [:function] name = function[:name] if tool = @tools[name] arguments = function[:arguments] result = tool.call(arguments) return { role: "tool", tool_name: name, content: result.to_json, } else raise ArgumentError.new("Unknown tool: #{name}") end rescue => error return { role: "tool", tool_name: name, error: error.inspect, } end |
#explain ⇒ Object
88 89 90 |
# File 'lib/async/ollama/toolbox.rb', line 88 def explain @tools.values.map(&:explain) end |
#register(name, schema, &block) ⇒ Object
Registers a new tool with the given name, schema, and block.
56 57 58 |
# File 'lib/async/ollama/toolbox.rb', line 56 def register(name, schema, &block) @tools[name] = Tool.new(name, schema, &block) end |
#The registered tools by name.=(registeredtoolsbyname. = (value)) ⇒ Object
50 |
# File 'lib/async/ollama/toolbox.rb', line 50 attr :tools |