Class: OmniAI::Tool::Object
- Inherits:
-
Object
- Object
- OmniAI::Tool::Object
- Defined in:
- lib/omniai/tool/object.rb
Overview
Represents a schema object.
Direct Known Subclasses
Constant Summary collapse
- TYPE =
'object'
Instance Attribute Summary collapse
Instance Method Summary collapse
- #initialize(properties: {}, required: [], description: nil) ⇒ OmniAI::Tool::Parameters constructor
- #parse(args) ⇒ Hash
- #serialize ⇒ Hash
Constructor Details
#initialize(properties: {}, required: [], description: nil) ⇒ OmniAI::Tool::Parameters
33 34 35 36 37 |
# File 'lib/omniai/tool/object.rb', line 33 def initialize(properties: {}, required: [], description: nil) @properties = properties @required = required @description = description end |
Instance Attribute Details
#description ⇒ String?
28 29 30 |
# File 'lib/omniai/tool/object.rb', line 28 def description @description end |
#properties ⇒ Hash
20 21 22 |
# File 'lib/omniai/tool/object.rb', line 20 def properties @properties end |
#required ⇒ Array<String>
24 25 26 |
# File 'lib/omniai/tool/object.rb', line 24 def required @required end |
Instance Method Details
#parse(args) ⇒ Hash
52 53 54 55 56 57 58 59 |
# File 'lib/omniai/tool/object.rb', line 52 def parse(args) result = {} @properties.each do |name, property| value = args[String(name)] result[name.intern] = property.parse(value) unless value.nil? end result end |
#serialize ⇒ Hash
40 41 42 43 44 45 46 47 |
# File 'lib/omniai/tool/object.rb', line 40 def serialize { type: TYPE, description: @description, properties: @properties.transform_values(&:serialize), required: @required, }.compact end |