Class: LlmCostTracker::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_cost_tracker/configuration.rb

Constant Summary collapse

OPENAI_COMPATIBLE_PROVIDERS =

Hostname => provider name for OpenAI-compatible APIs.

{
  "openrouter.ai" => "openrouter",
  "api.deepseek.com" => "deepseek"
}.freeze
BUDGET_EXCEEDED_BEHAVIORS =
%i[notify raise block_requests].freeze
STORAGE_ERROR_BEHAVIORS =
%i[ignore warn raise].freeze
UNKNOWN_PRICING_BEHAVIORS =
%i[ignore warn raise].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/llm_cost_tracker/configuration.rb', line 30

def initialize
  @enabled            = true
  @storage_backend    = :log
  @custom_storage     = nil
  @default_tags       = {}
  @on_budget_exceeded = nil
  @monthly_budget     = nil
  @budget_exceeded_behavior = :notify
  @storage_error_behavior = :warn
  @unknown_pricing_behavior = :warn
  @log_level          = :info
  @prices_file        = nil
  @pricing_overrides  = {}
  self.openai_compatible_providers = OPENAI_COMPATIBLE_PROVIDERS
end

Instance Attribute Details

#budget_exceeded_behaviorObject

Returns the value of attribute budget_exceeded_behavior.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def budget_exceeded_behavior
  @budget_exceeded_behavior
end

#custom_storageObject

Returns the value of attribute custom_storage.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def custom_storage
  @custom_storage
end

#default_tagsObject

Returns the value of attribute default_tags.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def default_tags
  @default_tags
end

#enabledObject

Returns the value of attribute enabled.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def enabled
  @enabled
end

#log_levelObject

Returns the value of attribute log_level.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def log_level
  @log_level
end

#monthly_budgetObject

Returns the value of attribute monthly_budget.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def monthly_budget
  @monthly_budget
end

#on_budget_exceededObject

Returns the value of attribute on_budget_exceeded.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def on_budget_exceeded
  @on_budget_exceeded
end

#openai_compatible_providersObject

Returns the value of attribute openai_compatible_providers.



28
29
30
# File 'lib/llm_cost_tracker/configuration.rb', line 28

def openai_compatible_providers
  @openai_compatible_providers
end

#prices_fileObject

Returns the value of attribute prices_file.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def prices_file
  @prices_file
end

#pricing_overridesObject

Returns the value of attribute pricing_overrides.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def pricing_overrides
  @pricing_overrides
end

#storage_backendObject

Returns the value of attribute storage_backend.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def storage_backend
  @storage_backend
end

#storage_error_behaviorObject

Returns the value of attribute storage_error_behavior.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def storage_error_behavior
  @storage_error_behavior
end

#unknown_pricing_behaviorObject

Returns the value of attribute unknown_pricing_behavior.



15
16
17
# File 'lib/llm_cost_tracker/configuration.rb', line 15

def unknown_pricing_behavior
  @unknown_pricing_behavior
end

Instance Method Details

#active_record?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/llm_cost_tracker/configuration.rb', line 54

def active_record?
  storage_backend == :active_record
end

#log?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/llm_cost_tracker/configuration.rb', line 58

def log?
  storage_backend == :log
end

#normalize_openai_compatible_providers!Object



50
51
52
# File 'lib/llm_cost_tracker/configuration.rb', line 50

def normalize_openai_compatible_providers!
  self.openai_compatible_providers = openai_compatible_providers
end