Class: Ace::Support::Models::Models::PricingInfo
- Inherits:
-
Object
- Object
- Ace::Support::Models::Models::PricingInfo
- Defined in:
- lib/ace/support/models/models/pricing_info.rb
Overview
Represents pricing information for a model (per million tokens)
Instance Attribute Summary collapse
-
#cache_read ⇒ Object
readonly
Returns the value of attribute cache_read.
-
#cache_write ⇒ Object
readonly
Returns the value of attribute cache_write.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#reasoning ⇒ Object
readonly
Returns the value of attribute reasoning.
Class Method Summary collapse
-
.from_hash(hash) ⇒ PricingInfo
Create from API hash.
Instance Method Summary collapse
-
#available? ⇒ Boolean
Check if pricing data is available.
-
#calculate(input_tokens:, output_tokens:, reasoning_tokens: 0) ⇒ Float
Calculate total cost for token counts.
-
#initialize(input: nil, output: nil, reasoning: nil, cache_read: nil, cache_write: nil) ⇒ PricingInfo
constructor
Initialize pricing info.
-
#to_h ⇒ Hash
Convert to hash.
Constructor Details
#initialize(input: nil, output: nil, reasoning: nil, cache_read: nil, cache_write: nil) ⇒ PricingInfo
Initialize pricing info
17 18 19 20 21 22 23 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 17 def initialize(input: nil, output: nil, reasoning: nil, cache_read: nil, cache_write: nil) @input = input @output = output @reasoning = reasoning @cache_read = cache_read @cache_write = cache_write end |
Instance Attribute Details
#cache_read ⇒ Object (readonly)
Returns the value of attribute cache_read.
9 10 11 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 9 def cache_read @cache_read end |
#cache_write ⇒ Object (readonly)
Returns the value of attribute cache_write.
9 10 11 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 9 def cache_write @cache_write end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
9 10 11 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 9 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
9 10 11 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 9 def output @output end |
#reasoning ⇒ Object (readonly)
Returns the value of attribute reasoning.
9 10 11 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 9 def reasoning @reasoning end |
Class Method Details
.from_hash(hash) ⇒ PricingInfo
Create from API hash
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 28 def self.from_hash(hash) return new if hash.nil? new( input: hash["input"], output: hash["output"], reasoning: hash["reasoning"], cache_read: hash["cache_read"], cache_write: hash["cache_write"] ) end |
Instance Method Details
#available? ⇒ Boolean
Check if pricing data is available
54 55 56 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 54 def available? input || output end |
#calculate(input_tokens:, output_tokens:, reasoning_tokens: 0) ⇒ Float
Calculate total cost for token counts
63 64 65 66 67 68 69 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 63 def calculate(input_tokens:, output_tokens:, reasoning_tokens: 0) total = 0.0 total += (input_tokens / 1_000_000.0) * input if input total += (output_tokens / 1_000_000.0) * output if output total += (reasoning_tokens / 1_000_000.0) * reasoning if reasoning && reasoning_tokens > 0 total end |
#to_h ⇒ Hash
Convert to hash
42 43 44 45 46 47 48 49 50 |
# File 'lib/ace/support/models/models/pricing_info.rb', line 42 def to_h { input: input, output: output, reasoning: reasoning, cache_read: cache_read, cache_write: cache_write }.compact end |