Class: ChatgptRb::Function
- Inherits:
-
Object
- Object
- ChatgptRb::Function
- Defined in:
- lib/chatgpt_rb/function.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#implementation ⇒ Object
Returns the value of attribute implementation.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Instance Method Summary collapse
- #as_json ⇒ Hash
-
#initialize(name: nil, description: nil, parameters: [], implementation: nil) ⇒ Function
constructor
A new instance of Function.
Constructor Details
#initialize(name: nil, description: nil, parameters: [], implementation: nil) ⇒ Function
Returns a new instance of Function.
9 10 11 12 13 14 |
# File 'lib/chatgpt_rb/function.rb', line 9 def initialize(name: nil, description: nil, parameters: [], implementation: nil) @name = name @description = description @parameters = parameters @implementation = implementation end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/chatgpt_rb/function.rb', line 3 def description @description end |
#implementation ⇒ Object
Returns the value of attribute implementation.
3 4 5 |
# File 'lib/chatgpt_rb/function.rb', line 3 def implementation @implementation end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/chatgpt_rb/function.rb', line 3 def name @name end |
#parameters ⇒ Object
Returns the value of attribute parameters.
3 4 5 |
# File 'lib/chatgpt_rb/function.rb', line 3 def parameters @parameters end |
Instance Method Details
#as_json ⇒ Hash
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/chatgpt_rb/function.rb', line 17 def as_json { name:, description:, parameters: { type: "object", properties: parameters.each_with_object({}) do |parameter, hash| hash[parameter.name] = parameter.as_json end, required: parameters.select(&:required?).map(&:name), }, }.compact end |