Class: Agentic::GenerationStats
- Inherits:
-
Object
- Object
- Agentic::GenerationStats
- Defined in:
- lib/agentic/generation_stats.rb
Overview
Value object representing statistics for an LLM generation
Instance Attribute Summary collapse
-
#completion_tokens ⇒ Integer
readonly
The number of completion tokens.
-
#id ⇒ String
readonly
The ID of the generation.
-
#prompt_tokens ⇒ Integer
readonly
The number of prompt tokens.
-
#raw_stats ⇒ Hash
readonly
The raw statistics from the API.
-
#total_tokens ⇒ Integer
readonly
The total number of tokens.
Class Method Summary collapse
-
.from_response(response) ⇒ GenerationStats
Creates a GenerationStats object from an API response.
Instance Method Summary collapse
-
#initialize(id:, prompt_tokens:, completion_tokens:, total_tokens:, raw_stats: {}) ⇒ GenerationStats
constructor
Initializes a new generation statistics object.
-
#to_h ⇒ Hash
Returns a hash representation of the generation statistics.
Constructor Details
#initialize(id:, prompt_tokens:, completion_tokens:, total_tokens:, raw_stats: {}) ⇒ GenerationStats
Initializes a new generation statistics object
27 28 29 30 31 32 33 |
# File 'lib/agentic/generation_stats.rb', line 27 def initialize(id:, prompt_tokens:, completion_tokens:, total_tokens:, raw_stats: {}) @id = id @prompt_tokens = prompt_tokens @completion_tokens = completion_tokens @total_tokens = total_tokens @raw_stats = raw_stats end |
Instance Attribute Details
#completion_tokens ⇒ Integer (readonly)
13 14 15 |
# File 'lib/agentic/generation_stats.rb', line 13 def completion_tokens @completion_tokens end |
#id ⇒ String (readonly)
7 8 9 |
# File 'lib/agentic/generation_stats.rb', line 7 def id @id end |
#prompt_tokens ⇒ Integer (readonly)
10 11 12 |
# File 'lib/agentic/generation_stats.rb', line 10 def prompt_tokens @prompt_tokens end |
#raw_stats ⇒ Hash (readonly)
19 20 21 |
# File 'lib/agentic/generation_stats.rb', line 19 def raw_stats @raw_stats end |
#total_tokens ⇒ Integer (readonly)
16 17 18 |
# File 'lib/agentic/generation_stats.rb', line 16 def total_tokens @total_tokens end |
Class Method Details
.from_response(response) ⇒ GenerationStats
Creates a GenerationStats object from an API response
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/agentic/generation_stats.rb', line 49 def self.from_response(response) usage = response&.dig("usage") || {} new( id: response&.dig("id") || "", prompt_tokens: usage["prompt_tokens"] || 0, completion_tokens: usage["completion_tokens"] || 0, total_tokens: usage["total_tokens"] || 0, raw_stats: response || {} ) end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the generation statistics
37 38 39 40 41 42 43 44 |
# File 'lib/agentic/generation_stats.rb', line 37 def to_h { id: @id, prompt_tokens: @prompt_tokens, completion_tokens: @completion_tokens, total_tokens: @total_tokens } end |