Class: AICallable::MethodSignatureBuilder
- Inherits:
-
Object
- Object
- AICallable::MethodSignatureBuilder
- Defined in:
- lib/glim_ai_callable.rb
Instance Attribute Summary collapse
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Instance Method Summary collapse
- #describe(text) ⇒ Object
-
#initialize ⇒ MethodSignatureBuilder
constructor
A new instance of MethodSignatureBuilder.
-
#number(name, description, opts = {}) ⇒ Object
null: A JSON “null” value boolean: A “true” or “false” value, from the JSON “true” or “false” value object: An unordered set of properties mapping a string to an instance, from the JSON “object” value array: An ordered list of instances, from the JSON “array” value number: An arbitrary-precision, base-10 decimal number value, from the JSON “number” value string: A string of Unicode code points, from the JSON “string” value.
- #string(name, description, opts = {}) ⇒ Object
Constructor Details
#initialize ⇒ MethodSignatureBuilder
Returns a new instance of MethodSignatureBuilder.
79 80 81 82 83 84 85 86 87 |
# File 'lib/glim_ai_callable.rb', line 79 def initialize @signature = { parameters: { type: "object", properties: {}, required: [] } } end |
Instance Attribute Details
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
89 90 91 |
# File 'lib/glim_ai_callable.rb', line 89 def signature @signature end |
Instance Method Details
#describe(text) ⇒ Object
91 92 93 |
# File 'lib/glim_ai_callable.rb', line 91 def describe(text) @signature[:description] = text end |
#number(name, description, opts = {}) ⇒ Object
null: A JSON “null” value boolean: A “true” or “false” value, from the JSON “true” or “false” value object: An unordered set of properties mapping a string to an instance, from the JSON “object” value array: An ordered list of instances, from the JSON “array” value number: An arbitrary-precision, base-10 decimal number value, from the JSON “number” value string: A string of Unicode code points, from the JSON “string” value
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/glim_ai_callable.rb', line 113 def number(name, description, opts = {}) # we want to use ai_name for everything here, but then when we invoke, # we will want to look up the local name ai_name = opts[:ai_name] || name @signature[:parameters][:properties][ai_name] = { type: :number, description: description, local_name: name } if opts[:required] raise "Required muat be boolean if set" unless opts[:required].is_a?(TrueClass) || opts[:required].is_a?(FalseClass) @signature[:parameters][:required] << ai_name if opts[:required] end end |
#string(name, description, opts = {}) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/glim_ai_callable.rb', line 128 def string(name, description, opts = {}) # we want to use ai_name for everything here, but then when we invoke, # we will want to look up the local name ai_name = opts[:ai_name] || name @signature[:parameters][:properties][ai_name] = { type: :string, description: description, local_name: name } if opts[:enum] rng = opts[:enum] for s in rng raise "Invalid enum value: #{s}" unless s.is_a?(String) end @signature[:parameters][:properties][ai_name][:enum] = rng end if opts[:required] raise "Required muat be boolean if set" unless opts[:required].is_a?(TrueClass) || opts[:required].is_a?(FalseClass) @signature[:parameters][:required] << ai_name if opts[:required] end end |