Class: LlmCostTracker::Configuration
Constant Summary
collapse
- OPENAI_COMPATIBLE_PROVIDERS =
{ "openrouter.ai" => "openrouter", "api.deepseek.com" => "deepseek" }.freeze
- BUDGET_EXCEEDED_BEHAVIORS =
%i[notify raise block_requests].freeze
- UNKNOWN_PRICING_BEHAVIORS =
%i[ignore warn raise].freeze
- SHARED_SCALAR_ATTRIBUTES =
%i[enabled 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
#instrument, #instrumented?
Constructor Details
Returns a new instance of Configuration.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/llm_cost_tracker/configuration.rb', line 35
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
@pricing_overrides = {}
@instrumented_integrations = []
@report_tag_breakdowns = []
@redacted_tag_keys = DEFAULT_REDACTED_TAG_KEYS.dup
self.openai_compatible_providers = OPENAI_COMPATIBLE_PROVIDERS
@finalized = false
end
|
Instance Method Details
56
57
58
59
|
# File 'lib/llm_cost_tracker/configuration.rb', line 56
def default_tags=(value)
ensure_shared_configuration_mutable!
@default_tags = value
end
|
#finalize! ⇒ Object
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/llm_cost_tracker/configuration.rb', line 95
def finalize!
@default_tags = deep_freeze(@default_tags || {})
@pricing_overrides = deep_freeze(@pricing_overrides || {})
@instrumented_integrations = deep_freeze(@instrumented_integrations || [])
@report_tag_breakdowns = deep_freeze(Array(@report_tag_breakdowns))
@redacted_tag_keys = deep_freeze(Array(@redacted_tag_keys))
@openai_compatible_providers = deep_freeze(@openai_compatible_providers || {})
@finalized = true
self
end
|
#finalized? ⇒ Boolean
106
107
108
|
# File 'lib/llm_cost_tracker/configuration.rb', line 106
def finalized?
@finalized
end
|
#openai_compatible_providers=(providers) ⇒ Object
61
62
63
64
|
# File 'lib/llm_cost_tracker/configuration.rb', line 61
def openai_compatible_providers=(providers)
ensure_shared_configuration_mutable!
@openai_compatible_providers = normalize_openai_compatible_providers(providers)
end
|
#pricing_overrides=(value) ⇒ Object
66
67
68
69
|
# File 'lib/llm_cost_tracker/configuration.rb', line 66
def pricing_overrides=(value)
ensure_shared_configuration_mutable!
@pricing_overrides = value
end
|
#redacted_tag_keys=(value) ⇒ Object
76
77
78
79
|
# File 'lib/llm_cost_tracker/configuration.rb', line 76
def redacted_tag_keys=(value)
ensure_shared_configuration_mutable!
@redacted_tag_keys = Array(value).map(&:to_s)
end
|
#report_tag_breakdowns=(value) ⇒ Object
71
72
73
74
|
# File 'lib/llm_cost_tracker/configuration.rb', line 71
def report_tag_breakdowns=(value)
ensure_shared_configuration_mutable!
@report_tag_breakdowns = Array(value).map { |key| Tags::Key.validate!(key, error_class: Error) }
end
|