Class: Candle::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/candle/tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, parameters: {}, &block) ⇒ Tool

Returns a new instance of Tool.



7
8
9
10
11
12
# File 'lib/candle/tool.rb', line 7

def initialize(name:, description:, parameters: {}, &block)
  @name = name
  @description = description
  @parameters = parameters
  @callable = block
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/candle/tool.rb', line 5

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/candle/tool.rb', line 5

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



5
6
7
# File 'lib/candle/tool.rb', line 5

def parameters
  @parameters
end

Instance Method Details

#call(arguments) ⇒ Object



14
15
16
# File 'lib/candle/tool.rb', line 14

def call(arguments)
  @callable.call(arguments)
end

#to_tool_definitionObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/candle/tool.rb', line 18

def to_tool_definition
  {
    "type" => "function",
    "function" => {
      "name" => @name,
      "description" => @description,
      "parameters" => @parameters
    }
  }
end