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
- .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
106 107 108 109 110 |
# File 'lib/omniai/tool/property.rb', line 106 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
45 46 47 |
# File 'lib/omniai/tool/property.rb', line 45 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
73 74 75 |
# File 'lib/omniai/tool/property.rb', line 73 def self.boolean(description: nil, enum: nil) new(type: Type::BOOLEAN, description:, enum:) end |
.integer(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
81 82 83 |
# File 'lib/omniai/tool/property.rb', line 81 def self.integer(description: nil, enum: nil) new(type: Type::INTEGER, description:, enum:) end |
.number(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
97 98 99 |
# File 'lib/omniai/tool/property.rb', line 97 def self.number(description: nil, enum: nil) new(type: Type::NUMBER, description:, enum:) end |
.object(properties: {}, required: [], description: nil) ⇒ OmniAI::Tool::Array
65 66 67 |
# File 'lib/omniai/tool/property.rb', line 65 def self.object(properties: {}, required: [], description: nil) OmniAI::Tool::Object.new(properties:, required:, description:) end |
.string(description: nil, enum: nil) ⇒ OmniAI::Tool::Property
89 90 91 |
# File 'lib/omniai/tool/property.rb', line 89 def self.string(description: nil, enum: nil) new(type: Type::STRING, description:, enum:) end |
Instance Method Details
#parse(value) ⇒ String, ...
128 129 130 131 132 133 134 135 |
# File 'lib/omniai/tool/property.rb', line 128 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
116 117 118 119 120 121 122 |
# File 'lib/omniai/tool/property.rb', line 116 def serialize { type: @type, description: @description, enum: @enum, }.compact end |