Class: RubynCode::Hooks::BuiltIn::CostTrackingHook
- Inherits:
-
Object
- Object
- RubynCode::Hooks::BuiltIn::CostTrackingHook
- Defined in:
- lib/rubyn_code/hooks/built_in.rb
Overview
Records cost data after each LLM call using the BudgetEnforcer.
Expects the :post_llm_call context to include:
- response: the raw API response hash (with :usage or "usage" key)
- budget_enforcer: an Observability::BudgetEnforcer instance (optional)
Instance Method Summary collapse
- #call(response:, **_kwargs) ⇒ void
-
#initialize(budget_enforcer:) ⇒ CostTrackingHook
constructor
A new instance of CostTrackingHook.
Constructor Details
#initialize(budget_enforcer:) ⇒ CostTrackingHook
Returns a new instance of CostTrackingHook.
15 16 17 |
# File 'lib/rubyn_code/hooks/built_in.rb', line 15 def initialize(budget_enforcer:) @budget_enforcer = budget_enforcer end |
Instance Method Details
#call(response:, **_kwargs) ⇒ void
This method returns an undefined value.
22 23 24 25 26 27 28 29 |
# File 'lib/rubyn_code/hooks/built_in.rb', line 22 def call(response:, **_kwargs) return unless @budget_enforcer usage = response[:usage] || response['usage'] return unless usage record_usage(response, usage) end |