Class: LlmCostTracker::Budget
- Inherits:
-
Object
- Object
- LlmCostTracker::Budget
- Defined in:
- lib/llm_cost_tracker/budget.rb
Constant Summary collapse
- WARNING_MUTEX =
Mutex.new
Class Method Summary collapse
Class Method Details
.check!(event) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/llm_cost_tracker/budget.rb', line 19 def check!(event) config = LlmCostTracker.configuration return unless config.monthly_budget return unless event[:cost] monthly_total = calculate_monthly_total(event[:cost][:total_cost]) return unless monthly_total > config.monthly_budget handle_exceeded(monthly_total: monthly_total, last_event: event) end |
.enforce! ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/llm_cost_tracker/budget.rb', line 8 def enforce! return unless LlmCostTracker.configuration.monthly_budget return unless behavior == :block_requests return warn_non_active_record_block_requests unless LlmCostTracker.configuration.active_record? monthly_total = calculate_monthly_total(0) return unless monthly_total >= LlmCostTracker.configuration.monthly_budget handle_exceeded(monthly_total: monthly_total) end |