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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/llm_cost_tracker/budget.rb', line 20 def check!(event) config = LlmCostTracker.configuration return unless config.monthly_budget return unless event.cost monthly_total = if config.active_record? active_record_monthly_total else event.cost.total_cost end 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 18 |
# File 'lib/llm_cost_tracker/budget.rb', line 8 def enforce! config = LlmCostTracker.configuration return unless config.monthly_budget return unless config.budget_exceeded_behavior == :block_requests return unless config.active_record? monthly_total = active_record_monthly_total return unless monthly_total >= config.monthly_budget handle_exceeded(monthly_total: monthly_total) end |