Class: OpenRouter::Tool
- Inherits:
-
Object
- Object
- OpenRouter::Tool
- Defined in:
- lib/open_router/tool.rb
Defined Under Namespace
Classes: ItemsBuilder, ParametersBuilder, ToolBuilder
Instance Attribute Summary collapse
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.define(&block) ⇒ Object
Class method for defining tools with a DSL.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(definition = {}) ⇒ Tool
constructor
A new instance of Tool.
- #name ⇒ Object
- #parameters ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(definition = {}) ⇒ Tool
Returns a new instance of Tool.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/open_router/tool.rb', line 7 def initialize(definition = {}) if definition.is_a?(Hash) && definition.key?(:function) @type = definition[:type] || "function" @function = definition[:function] elsif definition.is_a?(Hash) @type = "function" @function = definition else raise ArgumentError, "Tool definition must be a hash" end validate_definition! end |
Instance Attribute Details
#function ⇒ Object (readonly)
Returns the value of attribute function.
5 6 7 |
# File 'lib/open_router/tool.rb', line 5 def function @function end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/open_router/tool.rb', line 5 def type @type end |
Class Method Details
.define(&block) ⇒ Object
Class method for defining tools with a DSL
22 23 24 25 26 |
# File 'lib/open_router/tool.rb', line 22 def self.define(&block) builder = ToolBuilder.new builder.instance_eval(&block) if block_given? new(builder.to_h) end |
Instance Method Details
#description ⇒ Object
43 44 45 |
# File 'lib/open_router/tool.rb', line 43 def description @function[:description] end |
#name ⇒ Object
39 40 41 |
# File 'lib/open_router/tool.rb', line 39 def name @function[:name] end |
#parameters ⇒ Object
47 48 49 |
# File 'lib/open_router/tool.rb', line 47 def parameters @function[:parameters] end |
#to_h ⇒ Object
28 29 30 31 32 33 |
# File 'lib/open_router/tool.rb', line 28 def to_h { type: @type, function: @function } end |
#to_json(*args) ⇒ Object
35 36 37 |
# File 'lib/open_router/tool.rb', line 35 def to_json(*args) to_h.to_json(*args) end |