Class: OmniAI::Chat::Function
- Inherits:
-
Object
- Object
- OmniAI::Chat::Function
- Defined in:
- lib/omniai/chat/function.rb
Overview
A function that includes a name / arguments.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, arguments:) ⇒ Function
constructor
A new instance of Function.
- #inspect ⇒ String
- #serialize(context: nil) ⇒ Hash
Constructor Details
#initialize(name:, arguments:) ⇒ Function
Returns a new instance of Function.
15 16 17 18 |
# File 'lib/omniai/chat/function.rb', line 15 def initialize(name:, arguments:) @name = name @arguments = arguments end |
Instance Attribute Details
#arguments ⇒ Hash
11 12 13 |
# File 'lib/omniai/chat/function.rb', line 11 def arguments @arguments end |
#name ⇒ String
8 9 10 |
# File 'lib/omniai/chat/function.rb', line 8 def name @name end |
Class Method Details
.deserialize(data, context: nil) ⇒ Function
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/omniai/chat/function.rb', line 29 def self.deserialize(data, context: nil) deserialize = context&.deserializer(:function) return deserialize.call(data, context:) if deserialize name = data['name'] arguments = begin JSON.parse(data['arguments']) if data['arguments'] rescue JSON::ParserError data['arguments'] end new(name:, arguments:) end |
Instance Method Details
#inspect ⇒ String
21 22 23 |
# File 'lib/omniai/chat/function.rb', line 21 def inspect "#<#{self.class.name} name=#{name.inspect} arguments=#{arguments.inspect}>" end |
#serialize(context: nil) ⇒ Hash
46 47 48 49 50 51 52 53 54 |
# File 'lib/omniai/chat/function.rb', line 46 def serialize(context: nil) serializer = context&.serializer(:function) return serializer.call(self, context:) if serializer { name: @name, arguments: (JSON.generate(@arguments) if @arguments), } end |