Sha256: d47fe6a065c9098890e6fa401e711cd066b321e584bae883311a1f1f0dc8b524

Contents?: true

Size: 655 Bytes

Versions: 1

Compression:

Stored size: 655 Bytes

Contents

# frozen_string_literal: true

module GenAI
  class Result
    attr_reader :raw, :provider, :model, :values

    def initialize(provider:, model:, raw:, values:)
      @raw = raw
      @provider = provider
      @model = model
      @values = values
    end

    def value
      values.first
    end

    def prompt_tokens
      usage['prompt_tokens']
    end

    def completion_tokens
      if usage['completion_tokens'] ||
         (total_tokens && prompt_tokens)
        total_tokens.to_i - prompt_tokens.to_i
      end
    end

    def total_tokens
      usage['total_tokens']
    end

    private

    def usage
      raw['usage']
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gen-ai-0.1.0 lib/gen_ai/result.rb