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
STORAGE_BACKENDS =
%i[log active_record custom].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.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/llm_cost_tracker/configuration.rb', line 33

def initialize
  @enabled = true
  self.storage_backend = :log
  @custom_storage     = nil
  @default_tags       = {}
  @on_budget_exceeded = nil
  @monthly_budget     = nil
  self.budget_exceeded_behavior = :notify
  self.storage_error_behavior = :warn
  self.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

:notify, :raise, :block_requests



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

def budget_exceeded_behavior
  @budget_exceeded_behavior
end

#custom_storageObject

Returns the value of attribute custom_storage.



18
19
20
# File 'lib/llm_cost_tracker/configuration.rb', line 18

def custom_storage
  @custom_storage
end

#default_tagsObject

Returns the value of attribute default_tags.



18
19
20
# File 'lib/llm_cost_tracker/configuration.rb', line 18

def default_tags
  @default_tags
end

#enabledObject

Returns the value of attribute enabled.



18
19
20
# File 'lib/llm_cost_tracker/configuration.rb', line 18

def enabled
  @enabled
end

#log_levelObject

Returns the value of attribute log_level.



18
19
20
# File 'lib/llm_cost_tracker/configuration.rb', line 18

def log_level
  @log_level
end

#monthly_budgetObject

Returns the value of attribute monthly_budget.



18
19
20
# File 'lib/llm_cost_tracker/configuration.rb', line 18

def monthly_budget
  @monthly_budget
end

#on_budget_exceededObject

Returns the value of attribute on_budget_exceeded.



18
19
20
# File 'lib/llm_cost_tracker/configuration.rb', line 18

def on_budget_exceeded
  @on_budget_exceeded
end

#openai_compatible_providersObject

:notify, :raise, :block_requests



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

def openai_compatible_providers
  @openai_compatible_providers
end

#prices_fileObject

Returns the value of attribute prices_file.



18
19
20
# File 'lib/llm_cost_tracker/configuration.rb', line 18

def prices_file
  @prices_file
end

#pricing_overridesObject

Returns the value of attribute pricing_overrides.



18
19
20
# File 'lib/llm_cost_tracker/configuration.rb', line 18

def pricing_overrides
  @pricing_overrides
end

#storage_backendObject

:notify, :raise, :block_requests



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

def storage_backend
  @storage_backend
end

#storage_error_behaviorObject

:notify, :raise, :block_requests



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

def storage_error_behavior
  @storage_error_behavior
end

#unknown_pricing_behaviorObject

:notify, :raise, :block_requests



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

def unknown_pricing_behavior
  @unknown_pricing_behavior
end

Instance Method Details

#active_record?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/llm_cost_tracker/configuration.rb', line 88

def active_record?
  storage_backend == :active_record
end

#log?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/llm_cost_tracker/configuration.rb', line 92

def log?
  storage_backend == :log
end

#normalize_openai_compatible_providers!Object



84
85
86
# File 'lib/llm_cost_tracker/configuration.rb', line 84

def normalize_openai_compatible_providers!
  self.openai_compatible_providers = openai_compatible_providers
end