Class: Ragents::Tool::Parameter
- Inherits:
-
Object
- Object
- Ragents::Tool::Parameter
- Defined in:
- lib/ragents/tool.rb
Overview
Parameter definition
Constant Summary collapse
- TYPE_MAP =
{ string: "string", integer: "integer", number: "number", boolean: "boolean", array: "array", object: "object" }.freeze
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #coerce(value) ⇒ Object
-
#initialize(name:, type:, required: false, description: nil, default: nil, enum: nil) ⇒ Parameter
constructor
A new instance of Parameter.
- #to_json_schema ⇒ Object
Constructor Details
#initialize(name:, type:, required: false, description: nil, default: nil, enum: nil) ⇒ Parameter
Returns a new instance of Parameter.
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ragents/tool.rb', line 146 def initialize(name:, type:, required: false, description: nil, default: nil, enum: nil) @name = name @type = type.to_sym @required = required @description = description @default = default @enum = enum validate_type! end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
135 136 137 |
# File 'lib/ragents/tool.rb', line 135 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
135 136 137 |
# File 'lib/ragents/tool.rb', line 135 def description @description end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
135 136 137 |
# File 'lib/ragents/tool.rb', line 135 def enum @enum end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
135 136 137 |
# File 'lib/ragents/tool.rb', line 135 def name @name end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
135 136 137 |
# File 'lib/ragents/tool.rb', line 135 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
135 136 137 |
# File 'lib/ragents/tool.rb', line 135 def type @type end |
Instance Method Details
#coerce(value) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/ragents/tool.rb', line 165 def coerce(value) case @type when :string value.to_s when :integer Integer(value) when :number Float(value) when :boolean coerce_boolean(value) when :array Array(value) when :object value.is_a?(Hash) ? value : raise(ArgumentError, "Expected Hash for #{@name}") else value end end |
#to_json_schema ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/ragents/tool.rb', line 157 def to_json_schema schema = { type: TYPE_MAP[@type] } schema[:description] = @description if @description schema[:enum] = @enum if @enum schema[:default] = @default if @default schema end |