Class: OmniAI::Tool::Property
- Inherits:
-
Object
- Object
- OmniAI::Tool::Property
- Defined in:
- lib/omniai/tool/property.rb
Overview
A property used for a tool parameter.
Defined Under Namespace
Modules: Type
Instance Attribute Summary collapse
- #description ⇒ String? readonly
- #enum ⇒ Array<String>? readonly
- #type ⇒ String readonly
Class Method Summary collapse
- .array(items:, min_items: nil, max_items: nil, description: nil) ⇒ OmniAI::Tool::Array
- .boolean(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
- .build(kind, **args) ⇒ OmniAI::Tool::Property
- .integer(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
- .number(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
- .object(properties: {}, required: [], description: nil) ⇒ OmniAI::Tool::Array
- .string(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
Instance Method Summary collapse
- #initialize(type:, description: nil, enum: nil) ⇒ OmniAI::Tool::Property constructor
- #parse(value) ⇒ String, ...
- #serialize ⇒ Hash
Constructor Details
#initialize(type:, description: nil, enum: nil) ⇒ OmniAI::Tool::Property
119 120 121 122 123 |
# File 'lib/omniai/tool/property.rb', line 119 def initialize(type:, description: nil, enum: nil) @type = type @description = description @enum = enum end |
Instance Attribute Details
#description ⇒ String? (readonly)
26 27 28 |
# File 'lib/omniai/tool/property.rb', line 26 def description @description end |
#enum ⇒ Array<String>? (readonly)
29 30 31 |
# File 'lib/omniai/tool/property.rb', line 29 def enum @enum end |
#type ⇒ String (readonly)
23 24 25 |
# File 'lib/omniai/tool/property.rb', line 23 def type @type end |
Class Method Details
.array(items:, min_items: nil, max_items: nil, description: nil) ⇒ OmniAI::Tool::Array
58 59 60 |
# File 'lib/omniai/tool/property.rb', line 58 def self.array(items:, min_items: nil, max_items: nil, description: nil) OmniAI::Tool::Array.new(items:, description:, min_items:, max_items:) end |
.boolean(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
86 87 88 |
# File 'lib/omniai/tool/property.rb', line 86 def self.boolean(description: nil, enum: nil) new(type: Type::BOOLEAN, description:, enum:) end |
.build(kind, **args) ⇒ OmniAI::Tool::Property
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/omniai/tool/property.rb', line 33 def self.build(kind, **args) case kind when :array then array(**args) when :object then object(**args) when :boolean then boolean(**args) when :integer then integer(**args) when :string then string(**args) when :number then number(**args) end end |
.integer(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
94 95 96 |
# File 'lib/omniai/tool/property.rb', line 94 def self.integer(description: nil, enum: nil) new(type: Type::INTEGER, description:, enum:) end |
.number(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
110 111 112 |
# File 'lib/omniai/tool/property.rb', line 110 def self.number(description: nil, enum: nil) new(type: Type::NUMBER, description:, enum:) end |
.object(properties: {}, required: [], description: nil) ⇒ OmniAI::Tool::Array
78 79 80 |
# File 'lib/omniai/tool/property.rb', line 78 def self.object(properties: {}, required: [], description: nil) OmniAI::Tool::Object.new(properties:, required:, description:) end |
.string(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
102 103 104 |
# File 'lib/omniai/tool/property.rb', line 102 def self.string(description: nil, enum: nil) new(type: Type::STRING, description:, enum:) end |
Instance Method Details
#parse(value) ⇒ String, ...
141 142 143 144 145 146 147 148 |
# File 'lib/omniai/tool/property.rb', line 141 def parse(value) case @type when Type::INTEGER then Integer(value) when Type::STRING then String(value) when Type::NUMBER then Float(value) else value end end |
#serialize ⇒ Hash
129 130 131 132 133 134 135 |
# File 'lib/omniai/tool/property.rb', line 129 def serialize { type: @type, description: @description, enum: @enum, }.compact end |