Class: LlmCostTracker::Configuration
- Inherits:
-
Object
- Object
- LlmCostTracker::Configuration
- 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
- SHARED_SCALAR_ATTRIBUTES =
%i[ enabled custom_storage on_budget_exceeded monthly_budget log_level prices_file ].freeze
- SHARED_ENUM_ATTRIBUTES =
{ storage_backend: [STORAGE_BACKENDS, :log], budget_exceeded_behavior: [BUDGET_EXCEEDED_BEHAVIORS, :notify], storage_error_behavior: [STORAGE_ERROR_BEHAVIORS, :warn], unknown_pricing_behavior: [UNKNOWN_PRICING_BEHAVIORS, :warn] }.freeze
Instance Method Summary collapse
- #active_record? ⇒ Boolean
- #default_tags=(value) ⇒ Object
- #dup_for_configuration ⇒ Object
- #finalize! ⇒ Object
- #finalized? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #log? ⇒ Boolean
- #normalize_openai_compatible_providers! ⇒ Object
- #openai_compatible_providers=(providers) ⇒ Object
- #pricing_overrides=(value) ⇒ Object
- #report_tag_breakdowns=(value) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/llm_cost_tracker/configuration.rb', line 45 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 = {} @report_tag_breakdowns = [] self.openai_compatible_providers = OPENAI_COMPATIBLE_PROVIDERS @finalized = false end |
Instance Method Details
#active_record? ⇒ Boolean
125 |
# File 'lib/llm_cost_tracker/configuration.rb', line 125 def active_record? = storage_backend == :active_record |
#default_tags=(value) ⇒ Object
63 64 65 66 |
# File 'lib/llm_cost_tracker/configuration.rb', line 63 def (value) ensure_shared_configuration_mutable! @default_tags = value end |
#dup_for_configuration ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/llm_cost_tracker/configuration.rb', line 112 def dup_for_configuration copy = dup copy.instance_variable_set(:@default_tags, ValueHelpers.deep_dup(@default_tags || {})) copy.instance_variable_set(:@pricing_overrides, ValueHelpers.deep_dup(@pricing_overrides || {})) copy.instance_variable_set(:@report_tag_breakdowns, ValueHelpers.deep_dup(@report_tag_breakdowns || [])) copy.instance_variable_set( :@openai_compatible_providers, ValueHelpers.deep_dup(@openai_compatible_providers || {}) ) copy.instance_variable_set(:@finalized, false) copy end |
#finalize! ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/llm_cost_tracker/configuration.rb', line 101 def finalize! @default_tags = ValueHelpers.deep_freeze(@default_tags || {}) @pricing_overrides = ValueHelpers.deep_freeze(@pricing_overrides || {}) @report_tag_breakdowns = ValueHelpers.deep_freeze(Array(@report_tag_breakdowns)) @openai_compatible_providers = ValueHelpers.deep_freeze(@openai_compatible_providers || {}) @finalized = true self end |
#finalized? ⇒ Boolean
110 |
# File 'lib/llm_cost_tracker/configuration.rb', line 110 def finalized? = @finalized |
#log? ⇒ Boolean
126 |
# File 'lib/llm_cost_tracker/configuration.rb', line 126 def log? = storage_backend == :log |
#normalize_openai_compatible_providers! ⇒ Object
97 98 99 |
# File 'lib/llm_cost_tracker/configuration.rb', line 97 def normalize_openai_compatible_providers! self.openai_compatible_providers = openai_compatible_providers end |
#openai_compatible_providers=(providers) ⇒ Object
68 69 70 71 |
# File 'lib/llm_cost_tracker/configuration.rb', line 68 def openai_compatible_providers=(providers) ensure_shared_configuration_mutable! @openai_compatible_providers = normalize_openai_compatible_providers(providers) end |
#pricing_overrides=(value) ⇒ Object
73 74 75 76 |
# File 'lib/llm_cost_tracker/configuration.rb', line 73 def pricing_overrides=(value) ensure_shared_configuration_mutable! @pricing_overrides = value end |
#report_tag_breakdowns=(value) ⇒ Object
78 79 80 81 |
# File 'lib/llm_cost_tracker/configuration.rb', line 78 def report_tag_breakdowns=(value) ensure_shared_configuration_mutable! @report_tag_breakdowns = value end |