Class: GenAI::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gen_ai/core/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, model:, raw:, values:) ⇒ Result

Returns a new instance of Result.



7
8
9
10
11
12
# File 'lib/gen_ai/core/result.rb', line 7

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

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/gen_ai/core/result.rb', line 5

def model
  @model
end

#providerObject (readonly)

Returns the value of attribute provider.



5
6
7
# File 'lib/gen_ai/core/result.rb', line 5

def provider
  @provider
end

#rawObject (readonly)

Returns the value of attribute raw.



5
6
7
# File 'lib/gen_ai/core/result.rb', line 5

def raw
  @raw
end

#valuesObject (readonly)

Returns the value of attribute values.



5
6
7
# File 'lib/gen_ai/core/result.rb', line 5

def values
  @values
end

Instance Method Details

#completion_tokensObject



29
30
31
32
33
# File 'lib/gen_ai/core/result.rb', line 29

def completion_tokens
  return usage['completion_tokens'] if usage['completion_tokens']

  total_tokens.to_i - prompt_tokens.to_i if total_tokens && prompt_tokens
end

#prompt_tokensObject



25
26
27
# File 'lib/gen_ai/core/result.rb', line 25

def prompt_tokens
  usage['prompt_tokens']
end

#total_tokensObject



35
36
37
# File 'lib/gen_ai/core/result.rb', line 35

def total_tokens
  usage['total_tokens']
end

#value(format = :raw) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/gen_ai/core/result.rb', line 14

def value(format = :raw)
  case format
  when :raw
    values.first
  when :base64
    Base64.encode64(values.first)
  else
    raise "Unsupported format: #{format}"
  end
end