Class: I18nContextGenerator::RunMetrics
- Inherits:
-
Data
- Object
- Data
- I18nContextGenerator::RunMetrics
- Defined in:
- lib/i18n_context_generator/run_metrics.rb
Overview
Aggregates run-local provider and cache telemetry. Cost is an estimate based on documented standard list prices for the built-in default models.
Instance Attribute Summary collapse
-
#cache_hits ⇒ Object
readonly
Returns the value of attribute cache_hits.
-
#cost_model ⇒ Object
readonly
Returns the value of attribute cost_model.
-
#cost_pricing_as_of ⇒ Object
readonly
Returns the value of attribute cost_pricing_as_of.
-
#estimated_cost_usd ⇒ Object
readonly
Returns the value of attribute estimated_cost_usd.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
-
#request_count ⇒ Object
readonly
Returns the value of attribute request_count.
-
#retry_count ⇒ Object
readonly
Returns the value of attribute retry_count.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#cache_hits ⇒ Object (readonly)
Returns the value of attribute cache_hits
12 13 14 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 12 def cache_hits @cache_hits end |
#cost_model ⇒ Object (readonly)
Returns the value of attribute cost_model
12 13 14 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 12 def cost_model @cost_model end |
#cost_pricing_as_of ⇒ Object (readonly)
Returns the value of attribute cost_pricing_as_of
12 13 14 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 12 def cost_pricing_as_of @cost_pricing_as_of end |
#estimated_cost_usd ⇒ Object (readonly)
Returns the value of attribute estimated_cost_usd
12 13 14 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 12 def estimated_cost_usd @estimated_cost_usd end |
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens
12 13 14 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 12 def input_tokens @input_tokens end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens
12 13 14 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 12 def output_tokens @output_tokens end |
#request_count ⇒ Object (readonly)
Returns the value of attribute request_count
12 13 14 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 12 def request_count @request_count end |
#retry_count ⇒ Object (readonly)
Returns the value of attribute retry_count
12 13 14 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 12 def retry_count @retry_count end |
Class Method Details
.from(results, provider:, model:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 16 def self.from(results, provider:, model:) input_tokens = results.sum { |result| result.input_tokens.to_i } output_tokens = results.sum { |result| result.output_tokens.to_i } price = RUN_METRICS_PRICES_PER_MILLION[[provider.to_s, model.to_s]] estimated_cost = ((input_tokens * price[:input]) + (output_tokens * price[:output])) / 1_000_000.0 if price new( request_count: results.sum { |result| result.request_count.to_i }, cache_hits: results.count(&:cache_hit), input_tokens: input_tokens, output_tokens: output_tokens, retry_count: results.sum { |result| result.retries.to_i }, estimated_cost_usd: estimated_cost&.round(8), cost_model: price ? model.to_s : nil, cost_pricing_as_of: price ? RUN_METRICS_PRICING_AS_OF : nil ) end |
Instance Method Details
#to_h ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/i18n_context_generator/run_metrics.rb', line 34 def to_h { request_count: request_count, cache_hits: cache_hits, input_tokens: input_tokens, output_tokens: output_tokens, retry_count: retry_count, estimated_cost_usd: estimated_cost_usd, cost_model: cost_model, cost_pricing_as_of: cost_pricing_as_of } end |