Class: Intelligence::ChatResult
- Inherits:
-
Object
- Object
- Intelligence::ChatResult
- 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
-
#choices ⇒ Object
readonly
Returns the value of attribute choices.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
Instance Method Summary collapse
-
#initialize(chat_attributes) ⇒ ChatResult
constructor
A new instance of ChatResult.
- #message ⇒ Object
- #text ⇒ Object
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
#choices ⇒ Object (readonly)
Returns the value of attribute choices.
12 13 14 |
# File 'lib/intelligence/chat_result.rb', line 12 def choices @choices end |
#metrics ⇒ Object (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
#message ⇒ Object
25 26 27 28 |
# File 'lib/intelligence/chat_result.rb', line 25 def return nil if @choices.empty? @choices.first. end |
#text ⇒ Object
30 31 32 |
# File 'lib/intelligence/chat_result.rb', line 30 def text return self.&.text || '' end |