Class: LLM::Cost

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#input_costsFloat

Returns the input cost

Returns:

  • (Float)

    the current value of input_costs



12
13
14
# File 'lib/llm/cost.rb', line 12

def input_costs
  @input_costs
end

#output_costsFloat

Returns the output cost

Returns:

  • (Float)

    the current value of output_costs



12
13
14
# File 'lib/llm/cost.rb', line 12

def output_costs
  @output_costs
end

Instance Method Details

#totalFloat

Returns the total cost

Returns:

  • (Float)

    Returns the total cost



16
17
18
# File 'lib/llm/cost.rb', line 16

def total
  input_costs + output_costs
end

#to_sString

Returns the total cost in a human friendly format

Returns:

  • (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