Class: Insika::Refinement::Budget

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/refinement/panel.rb

Overview

What a refinement run is allowed to SPEND.

A panel of 3 proposers over a 7-case golden set is 3 model calls plus 21 replayed conversations, each a real turn with real tools. That is the honest objection to the whole feature, and this is the answer to it: a ceiling the operator sets, checked before each expensive step and never in the middle of one. Nothing is aborted mid-flight — a half-scored candidate is worse than an unscored one, because it looks like a verdict.

Unmetered legs are counted, not guessed. A provider that reports no token usage makes a leg invisible to the ceiling; recording it as 0 would let a budget sit at "0 spent" forever while real money went out, so those legs are tallied separately and shown to the operator. The structural bounds — the fan-out cap on the panel, max_edits, the gate's own refusals — are what bound a run whose provider says nothing.

Instance Method Summary collapse

Constructor Details

#initialize(tokens: nil) ⇒ Budget

Returns a new instance of Budget.



21
22
23
24
25
26
27
# File 'lib/insika/refinement/panel.rb', line 21

def initialize(tokens: nil)
  limit = tokens.to_i
  @limit = limit.positive? ? limit : nil
  @spent = 0
  @cached = 0
  @unmetered = 0
end

Instance Method Details

#exhausted?Boolean

Returns:

  • (Boolean)


47
# File 'lib/insika/refinement/panel.rb', line 47

def exhausted? = limited? && @spent >= @limit

#limited?Boolean

Returns:

  • (Boolean)


29
# File 'lib/insika/refinement/panel.rb', line 29

def limited? = !@limit.nil?

#remainingObject



49
# File 'lib/insika/refinement/panel.rb', line 49

def remaining = limited? ? [@limit - @spent, 0].max : nil

#spend(tokens, cached: nil) ⇒ Object

tokens is what the leg SENT, prompt cache included — see Evals::Runner#billed_tokens for why the engine's total_tokens alone is not that number. cached is the part of it that was cached, carried so the record can explain a total rather than just state one. nil/0 tokens = the leg happened and reported nothing.



36
37
38
39
40
41
42
43
44
45
# File 'lib/insika/refinement/panel.rb', line 36

def spend(tokens, cached: nil)
  count = tokens.to_i
  if count.positive?
    @spent += count
    @cached += cached.to_i
  else
    @unmetered += 1
  end
  self
end

#to_hObject



51
52
# File 'lib/insika/refinement/panel.rb', line 51

def to_h = { "tokens" => @limit, "spent" => @spent, "cached" => @cached,
"unmetered" => @unmetered }