Class: OmniAI::Tool::Parameters
- Inherits:
-
Object
- Object
- OmniAI::Tool::Parameters
- Defined in:
- lib/omniai/tool/parameters.rb
Overview
Usage:
parameters = OmniAI::Tool::Parameters.new(properties:
n: OmniAI::Tool::Parameters.integer(description: 'The nth number to calculate.')
required: %i[n]
)
Defined Under Namespace
Modules: Type
Instance Method Summary collapse
- #initialize(type: Type::OBJECT, properties: {}, required: []) ⇒ OmniAI::Tool::Parameters constructor
- #parse(args) ⇒ Hash
- #prepare ⇒ Hash
Constructor Details
#initialize(type: Type::OBJECT, properties: {}, required: []) ⇒ OmniAI::Tool::Parameters
20 21 22 23 24 |
# File 'lib/omniai/tool/parameters.rb', line 20 def initialize(type: Type::OBJECT, properties: {}, required: []) @type = type @properties = properties @required = required end |
Instance Method Details
#parse(args) ⇒ Hash
37 38 39 40 41 42 43 44 |
# File 'lib/omniai/tool/parameters.rb', line 37 def parse(args) result = {} @properties.each do |name, property| value = args[String(name)] result[name.intern] = property.parse(value) if value end result end |
#prepare ⇒ Hash
27 28 29 30 31 32 33 |
# File 'lib/omniai/tool/parameters.rb', line 27 def prepare { type: @type, properties: @properties.transform_values(&:prepare), required: @required, }.compact end |