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
- INGESTION_MODES =
%i[inline async].freeze
- 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 ingestion_pool_size auto_enable_stream_usage cache_rollups].freeze
- ENUM_ATTRIBUTES =
{ budget_exceeded_behavior: [BUDGET_EXCEEDED_BEHAVIORS, :notify], unknown_pricing_behavior: [UNKNOWN_PRICING_BEHAVIORS, :warn], ingestion: [INGESTION_MODES, :inline] }.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
- #normalized_redacted_tag_keys ⇒ Object
- #openai_compatible_providers=(providers) ⇒ Object
- #pricing_overrides=(value) ⇒ Object
- #redacted_tag_keys=(value) ⇒ Object
- #report_tag_breakdowns=(value) ⇒ Object
- #static_sanitized_default_tags ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/llm_cost_tracker/configuration.rb', line 40 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 @ingestion_pool_size = nil 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 @auto_enable_stream_usage = true self.ingestion = :inline @cache_rollups = false @finalized = false end |
Instance Method Details
#finalize! ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/llm_cost_tracker/configuration.rb', line 112 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 end |
#finalized? ⇒ Boolean
135 136 137 |
# File 'lib/llm_cost_tracker/configuration.rb', line 135 def finalized? @finalized end |
#instrument(*names) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/llm_cost_tracker/configuration.rb', line 87 def instrument(*names) ensure_mutable! names = names.flatten names = Integrations.names if names == [:all] @instrumented_integrations.merge(names) end |
#instrumented?(name) ⇒ Boolean
94 95 96 |
# File 'lib/llm_cost_tracker/configuration.rb', line 94 def instrumented?(name) @instrumented_integrations.include?(name) end |
#normalized_redacted_tag_keys ⇒ Object
124 125 126 127 |
# File 'lib/llm_cost_tracker/configuration.rb', line 124 def normalized_redacted_tag_keys @normalized_redacted_tag_keys ||= Array(@redacted_tag_keys).map { |key| Tags::Sanitizer.normalized_key(key) }.freeze end |
#openai_compatible_providers=(providers) ⇒ Object
65 66 67 68 |
# File 'lib/llm_cost_tracker/configuration.rb', line 65 def openai_compatible_providers=(providers) ensure_mutable! @openai_compatible_providers = normalize_openai_compatible_providers(providers) end |
#pricing_overrides=(value) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/llm_cost_tracker/configuration.rb', line 70 def pricing_overrides=(value) ensure_mutable! @pricing_overrides = Pricing::Registry.normalize_price_entries(value || {}, context: "pricing_overrides") rescue ArgumentError, TypeError => e raise Error, "invalid pricing_overrides: #{e.}" end |
#redacted_tag_keys=(value) ⇒ Object
82 83 84 85 |
# File 'lib/llm_cost_tracker/configuration.rb', line 82 def redacted_tag_keys=(value) ensure_mutable! @redacted_tag_keys = Array(value).map(&:to_s) end |