Class: LlmCostTracker::Budget
- Inherits:
-
Object
- Object
- LlmCostTracker::Budget
- Defined in:
- lib/llm_cost_tracker/budget.rb
Class Method Summary collapse
Class Method Details
.check!(event) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/llm_cost_tracker/budget.rb', line 22 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
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/llm_cost_tracker/budget.rb', line 11 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 |