Sha256: 059e847d8d13c05dc600ab3e808b4fd7b232d7f459f43aa3c083ee0250d11941
Contents?: true
Size: 1.24 KB
Versions: 20
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module OmniAI class Chat # A usage returned by the API. class Usage attr_accessor :input_tokens, :output_tokens, :total_tokens # @param data [Hash] # @return [OmniAI::Chat::Usage] def self.for(data:) input_tokens = data['input_tokens'] || data['prompt_tokens'] output_tokens = data['output_tokens'] || data['completion_tokens'] total_tokens = data['total_tokens'] || (input_tokens + output_tokens) new( input_tokens:, output_tokens:, total_tokens: ) end # @param input_tokens [Integer] # @param output_tokens [Integer] # @param total_tokens [Integer] def initialize(input_tokens:, output_tokens:, total_tokens:) @input_tokens = input_tokens @output_tokens = output_tokens @total_tokens = total_tokens end # @return [Integer] def completion_tokens @output_tokens end # @return [Integer] def prompt_tokens @input_tokens end # @return [String] def inspect "#<#{self.class.name} input_tokens=#{input_tokens} output_tokens=#{output_tokens} total_tokens=#{total_tokens}>" end end end end
Version data entries
20 entries across 20 versions & 1 rubygems