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
- 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 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],
storage_error_behavior: [STORAGE_ERROR_BEHAVIORS, :warn],
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
#storage_backend=
#instrument, #instrumented?
Constructor Details
Returns a new instance of Configuration.
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/llm_cost_tracker/configuration.rb', line 43
def initialize
@enabled = true
self.storage_backend = :log
@custom_storage = nil
@default_tags = {}
@on_budget_exceeded = nil
@monthly_budget = nil
@daily_budget = nil
@per_call_budget = nil
self.budget_exceeded_behavior = :notify
self.storage_error_behavior = :warn
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
#active_record? ⇒ Boolean
137
|
# File 'lib/llm_cost_tracker/configuration.rb', line 137
def active_record? = storage_backend == :active_record
|
67
68
69
70
|
# File 'lib/llm_cost_tracker/configuration.rb', line 67
def default_tags=(value)
ensure_shared_configuration_mutable!
@default_tags = value
end
|
#dup_for_configuration ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/llm_cost_tracker/configuration.rb', line 119
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(
:@instrumented_integrations,
ValueHelpers.deep_dup(@instrumented_integrations || [])
)
copy.instance_variable_set(:@report_tag_breakdowns, ValueHelpers.deep_dup(@report_tag_breakdowns || []))
copy.instance_variable_set(:@redacted_tag_keys, ValueHelpers.deep_dup(@redacted_tag_keys || []))
copy.instance_variable_set(
:@openai_compatible_providers,
ValueHelpers.deep_dup(@openai_compatible_providers || {})
)
copy.instance_variable_set(:@finalized, false)
copy
end
|
#finalized? ⇒ Boolean
117
|
# File 'lib/llm_cost_tracker/configuration.rb', line 117
def finalized? = @finalized
|
#openai_compatible_providers=(providers) ⇒ Object
72
73
74
75
|
# File 'lib/llm_cost_tracker/configuration.rb', line 72
def openai_compatible_providers=(providers)
ensure_shared_configuration_mutable!
@openai_compatible_providers = normalize_openai_compatible_providers(providers)
end
|
#pricing_overrides=(value) ⇒ Object
77
78
79
80
|
# File 'lib/llm_cost_tracker/configuration.rb', line 77
def pricing_overrides=(value)
ensure_shared_configuration_mutable!
@pricing_overrides = value
end
|
#redacted_tag_keys=(value) ⇒ Object
87
88
89
90
|
# File 'lib/llm_cost_tracker/configuration.rb', line 87
def redacted_tag_keys=(value)
ensure_shared_configuration_mutable!
@redacted_tag_keys = Array(value).map(&:to_s)
end
|
#report_tag_breakdowns=(value) ⇒ Object
82
83
84
85
|
# File 'lib/llm_cost_tracker/configuration.rb', line 82
def report_tag_breakdowns=(value)
ensure_shared_configuration_mutable!
@report_tag_breakdowns = normalize_report_tag_breakdowns(value)
end
|