Class: LLM::Cost
- Inherits:
-
Struct
- Object
- Struct
- LLM::Cost
- Defined in:
- lib/llm/cost.rb
Overview
The LLM::Cost class represents an approximate cost breakdown for a provider request. It stores the input and output costs separately and can return the total.
Instance Attribute Summary collapse
-
#input_costs ⇒
Float
Returns the input cost.
-
#output_costs ⇒
Float
Returns the output cost.
Instance Method Summary collapse
-
#total ⇒
Float
Returns the total cost.
-
#to_s ⇒
String
Returns the total cost in a human friendly format.
Instance Attribute Details
#input_costs ⇒ Float
Returns the input cost
12 13 14 |
# File 'lib/llm/cost.rb', line 12 def input_costs @input_costs end |
#output_costs ⇒ Float
Returns the output cost
12 13 14 |
# File 'lib/llm/cost.rb', line 12 def output_costs @output_costs end |
Instance Method Details
#total ⇒ Float
Returns the total cost
16 17 18 |
# File 'lib/llm/cost.rb', line 16 def total input_costs + output_costs end |
#to_s ⇒ String
Returns the total cost in a human friendly format
23 24 25 |
# File 'lib/llm/cost.rb', line 23 def to_s format("%.12f", total).sub(/\.?0+$/, "") end |