Class: LlmCostTracker::Configuration
- Inherits:
-
Object
- Object
- LlmCostTracker::Configuration
- Defined in:
- lib/llm_cost_tracker/configuration.rb
Constant Summary collapse
- OPENAI_COMPATIBLE_PROVIDERS =
{ "openrouter.ai" => "openrouter", "api.deepseek.com" => "deepseek", "api.groq.com" => "groq" }.freeze
- BUDGET_EXCEEDED_BEHAVIORS =
%i[notify raise block_requests].freeze
- UNKNOWN_PRICING_BEHAVIORS =
%i[ignore warn raise].freeze
- SHARED_SCALAR_ATTRIBUTES =
%i[enabled default_tags on_budget_exceeded monthly_budget daily_budget per_call_budget log_level prices_file max_tag_count max_tag_value_bytesize].freeze
- SHARED_ENUM_ATTRIBUTES =
{ budget_exceeded_behavior: [BUDGET_EXCEEDED_BEHAVIORS, :notify], unknown_pricing_behavior: [UNKNOWN_PRICING_BEHAVIORS, :warn] }.freeze
- DEFAULT_REDACTED_TAG_KEYS =
%w[api_key access_token authorization credential password refresh_token secret].freeze
Instance Method Summary collapse
- #finalize! ⇒ Object
- #finalized? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #instrument(*names) ⇒ Object
- #instrumented?(name) ⇒ Boolean
- #openai_compatible_providers=(providers) ⇒ Object
- #pricing_overrides=(value) ⇒ Object
- #redacted_tag_keys=(value) ⇒ Object
- #report_tag_breakdowns=(value) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/llm_cost_tracker/configuration.rb', line 36 def initialize @enabled = true @default_tags = {} @on_budget_exceeded = nil @monthly_budget = nil @daily_budget = nil @per_call_budget = nil self.budget_exceeded_behavior = :notify self.unknown_pricing_behavior = :warn @log_level = :info @prices_file = nil @max_tag_count = 50 @max_tag_value_bytesize = 1024 self.pricing_overrides = {} @instrumented_integrations = Set.new @report_tag_breakdowns = [] @redacted_tag_keys = DEFAULT_REDACTED_TAG_KEYS.dup self.openai_compatible_providers = OPENAI_COMPATIBLE_PROVIDERS @finalized = false end |
Instance Method Details
#finalize! ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/llm_cost_tracker/configuration.rb', line 102 def finalize! @default_tags = deep_freeze(@default_tags || {}) @pricing_overrides = deep_freeze(@pricing_overrides || {}) @instrumented_integrations = deep_freeze(@instrumented_integrations || Set.new) @report_tag_breakdowns = deep_freeze(Array(@report_tag_breakdowns)) @redacted_tag_keys = deep_freeze(Array(@redacted_tag_keys)) @openai_compatible_providers = deep_freeze( normalize_openai_compatible_providers(@openai_compatible_providers) ) @finalized = true self end |
#finalized? ⇒ Boolean
115 116 117 |
# File 'lib/llm_cost_tracker/configuration.rb', line 115 def finalized? @finalized end |
#instrument(*names) ⇒ Object
79 80 81 82 |
# File 'lib/llm_cost_tracker/configuration.rb', line 79 def instrument(*names) ensure_shared_configuration_mutable! @instrumented_integrations.merge(normalize_instrumentation_names(names)) end |
#instrumented?(name) ⇒ Boolean
84 85 86 |
# File 'lib/llm_cost_tracker/configuration.rb', line 84 def instrumented?(name) @instrumented_integrations.include?(name) end |
#openai_compatible_providers=(providers) ⇒ Object
57 58 59 60 |
# File 'lib/llm_cost_tracker/configuration.rb', line 57 def openai_compatible_providers=(providers) ensure_shared_configuration_mutable! @openai_compatible_providers = normalize_openai_compatible_providers(providers) end |
#pricing_overrides=(value) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/llm_cost_tracker/configuration.rb', line 62 def pricing_overrides=(value) ensure_shared_configuration_mutable! @pricing_overrides = Pricing::Registry.normalize_price_table(value || {}) rescue ArgumentError => e raise Error, "invalid pricing_overrides: #{e.}" end |
#redacted_tag_keys=(value) ⇒ Object
74 75 76 77 |
# File 'lib/llm_cost_tracker/configuration.rb', line 74 def redacted_tag_keys=(value) ensure_shared_configuration_mutable! @redacted_tag_keys = Array(value).map(&:to_s) end |