Class: GenAI::Result
- Inherits:
-
Object
- Object
- GenAI::Result
- Defined in:
- lib/gen_ai/core/result.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #completion_tokens ⇒ Object
-
#initialize(provider:, model:, raw:, values:) ⇒ Result
constructor
A new instance of Result.
- #prompt_tokens ⇒ Object
- #total_tokens ⇒ Object
- #value(format = :raw) ⇒ Object
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
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/gen_ai/core/result.rb', line 5 def model @model end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
5 6 7 |
# File 'lib/gen_ai/core/result.rb', line 5 def provider @provider end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
5 6 7 |
# File 'lib/gen_ai/core/result.rb', line 5 def raw @raw end |
#values ⇒ Object (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_tokens ⇒ Object
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_tokens ⇒ Object
25 26 27 |
# File 'lib/gen_ai/core/result.rb', line 25 def prompt_tokens usage['prompt_tokens'] end |
#total_tokens ⇒ Object
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 |