Class: RubyLLM::Tool
- Inherits:
-
Object
- Object
- RubyLLM::Tool
- Defined in:
- lib/ruby_llm/tool.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.description(text = nil) ⇒ Object
17 18 19 20 21 |
# File 'lib/ruby_llm/tool.rb', line 17 def description(text = nil) return @description unless text @description = text end |
.param(name, **options) ⇒ Object
23 24 25 |
# File 'lib/ruby_llm/tool.rb', line 23 def param(name, **) parameters[name] = Parameter.new(name, **) end |
.parameters ⇒ Object
27 28 29 |
# File 'lib/ruby_llm/tool.rb', line 27 def parameters @parameters ||= {} end |
Instance Method Details
#call(args) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/ruby_llm/tool.rb', line 48 def call(args) RubyLLM.logger.debug "Tool #{name} called with: #{args.inspect}" result = execute(**args.transform_keys(&:to_sym)) RubyLLM.logger.debug "Tool #{name} returned: #{result.inspect}" result rescue StandardError => e RubyLLM.logger.error "Tool #{name} failed with error: #{e.}" { error: e. } end |
#description ⇒ Object
40 41 42 |
# File 'lib/ruby_llm/tool.rb', line 40 def description self.class.description end |
#execute ⇒ Object
58 59 60 |
# File 'lib/ruby_llm/tool.rb', line 58 def execute(...) raise NotImplementedError, 'Subclasses must implement #execute' end |
#name ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/ruby_llm/tool.rb', line 32 def name self.class.name .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase .delete_suffix('_tool') end |
#parameters ⇒ Object
44 45 46 |
# File 'lib/ruby_llm/tool.rb', line 44 def parameters self.class.parameters end |