Class: Intelligence::ChatResult

Inherits:
Object
  • Object
show all
Defined in:
lib/intelligence/chat_result.rb

Overview

class. ChatResult

The ChatResult class encapsulates a successful result to a chat or stream request. A result includes an array of choices ( it is an array even if there is a single choice ) and the metrics associated with the generation of all result choices.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chat_attributes) ⇒ ChatResult

Returns a new instance of ChatResult.



15
16
17
18
19
20
21
22
23
# File 'lib/intelligence/chat_result.rb', line 15

def initialize( chat_attributes )

  @choices = []
  chat_attributes[ :choices ]&.each do | json_choice |
    @choices.push( ChatResultChoice.new( json_choice ) )
  end
  @metrics = ChatMetrics.new( chat_attributes[ :metrics ] ) \
    if chat_attributes.key?( :metrics )
end

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



12
13
14
# File 'lib/intelligence/chat_result.rb', line 12

def choices
  @choices
end

#metricsObject (readonly)

Returns the value of attribute metrics.



13
14
15
# File 'lib/intelligence/chat_result.rb', line 13

def metrics
  @metrics
end

Instance Method Details

#messageObject



25
26
27
28
# File 'lib/intelligence/chat_result.rb', line 25

def message 
  return nil if @choices.empty?
  @choices.first.message
end

#textObject



30
31
32
# File 'lib/intelligence/chat_result.rb', line 30

def text 
  return self.message&.text || ''
end