Module: OmniAI::Google::Chat::UsageSerializer

Defined in:
lib/omniai/google/chat/usage_serializer.rb

Overview

Overrides usage serialize / deserialize.

Class Method Summary collapse

Class Method Details

.deserialize(data) ⇒ OmniAI::Chat::Usage

Parameters:

  • data (Hash)

Returns:

  • (OmniAI::Chat::Usage)


20
21
22
23
24
25
# File 'lib/omniai/google/chat/usage_serializer.rb', line 20

def self.deserialize(data, *)
  input_tokens = data['promptTokenCount']
  output_tokens = data['candidatesTokenCount']
  total_tokens = data['totalTokenCount']
  OmniAI::Chat::Usage.new(input_tokens:, output_tokens:, total_tokens:)
end

.serialize(usage) ⇒ Hash

Parameters:

  • usage (OmniAI::Chat::Usage)

Returns:

  • (Hash)


10
11
12
13
14
15
16
# File 'lib/omniai/google/chat/usage_serializer.rb', line 10

def self.serialize(usage, *)
  {
    promptTokenCount: usage.input_tokens,
    candidatesTokenCount: usage.output_tokens,
    totalTokenCount: usage.total_tokens,
  }
end