Class: Intelligence::ChatMetrics

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

Overview

class. ChatMetrics

The ChatMetrics class encapsulates metrics information. These metrics include the number of input tokens consumed, the number of output tokens generated, the total number of tokens, and the duration of the request in milliseconds.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ChatMetrics

Returns a new instance of ChatMetrics.



18
19
20
21
22
# File 'lib/intelligence/chat_metrics.rb', line 18

def initialize( attributes )
  attributes.each do | key, value |
    instance_variable_set( "@#{key}", value ) if self.respond_to?( "#{key}" )
  end
end

Instance Attribute Details

#durationObject (readonly)




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

def duration
  @duration
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens.



15
16
17
# File 'lib/intelligence/chat_metrics.rb', line 15

def input_tokens
  @input_tokens
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens.



16
17
18
# File 'lib/intelligence/chat_metrics.rb', line 16

def output_tokens
  @output_tokens
end

Instance Method Details

#total_tokensObject



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

def total_tokens
  @total_tokens = @input_tokens + @output_tokens \
    if @total_tokens.nil? && @input_tokens && @output_tokens 
  @total_tokens
end