Documentation
¶
Overview ¶
Package cases is the exhaustive list of test cases the implementation must meet (testing.md §10). A case holds only what the spec decides: the input and the expected result. It never holds the current code's figure; the agreement test computes that each time it runs.
The JSON files in this directory are written by ../gen/gen_cases.py, which computes the body hashes.
Index ¶
- Variables
- func RoundMicros(p int64) int64
- func SectionTokens(b accountant.Body) (tools, system, messages int)
- func Tokens(b accountant.Body) int
- type Begin
- type Case
- type End
- type Expected
- type ExpectedCompaction
- type ExpectedEffect
- type ExpectedOp
- type ExpectedUnpriced
- type Facts
- type Rate
- type Step
Constants ¶
This section is empty.
Variables ¶
var Rates = map[string]Rate{
"fixture-v1": {Input: 3_000_000, CacheWrite5m: 3_750_000, CacheWrite1h: 6_000_000, CacheRead: 300_000, Output: 15_000_000},
"summarizer-v1": {Input: 1_000_000, CacheWrite5m: 1_250_000, CacheWrite1h: 2_000_000, CacheRead: 100_000, Output: 5_000_000},
"small-model-v1": {Input: 800_000, CacheWrite5m: 1_000_000, CacheWrite1h: 1_600_000, CacheRead: 80_000, Output: 4_000_000},
}
Rates are the fixed rate tables a case may name (testing.md §10.2). With one table, the expected figure and the current code's figure can be compared in dollars.
Functions ¶
func RoundMicros ¶
RoundMicros rounds pico-dollars to micro-dollars, half up.
func SectionTokens ¶
func SectionTokens(b accountant.Body) (tools, system, messages int)
SectionTokens returns the tokens of each section of a body. The fixtures use 4 bytes a token, and 1 token for each 250 bytes of base64 media and of opaque bytes (a thinking signature) that the host did not count. Counted opaque bytes cost the host's count.
Types ¶
type Begin ¶
type Begin struct {
Meta accountant.RequestMeta `json:"meta"`
Client accountant.Body `json:"client"`
ClientBreakpoints []accountant.Breakpoint `json:"clientBreakpoints"`
}
Begin is the argument of Trackers.BeginRequest.
type Case ¶
type Case struct {
ID string `json:"id"`
// Description says what the case tests and where its figures come from, in plain words.
Description string `json:"description"`
Source string `json:"source,omitempty"` // the document the figures come from
Dims map[string]string `json:"dims"`
// Open names the spec's open questions (§11) that the expected figures depend on. Such a case
// is not frozen: the question's answer may change it.
Open []string `json:"open,omitempty"`
Rates string `json:"rates"` // names a rate table in Rates
Steps []Step `json:"steps"`
}
Case is one test case (testing.md §10.2): a sequence of steps on a fresh Trackers, because the result of a request depends on the ones before it (D14).
func All ¶
func All() []Case
All returns every case, sorted by ID. It panics on a malformed file, because the list is data the package ships and a bad file is a bug in the package. The exception is a fixture whose figure overflows a 32-bit int (GOARCH=386, accountant#134): All skips that file there instead, with a log/slog warning, because the figure is a platform limit, not a malformed file.
func (Case) ModelRate ¶
ModelRate says which table prices a model named on a request or on a ModelCall. The agent model and the large model are priced by the case's own table.
func (Case) StepPicos ¶
StepPicos is the expected net of one step: Saved minus Caused over its ops, priced with the case's rates, minus the cost of every spend, priced with its own model's rates.
func (Case) StepRate ¶
StepRate is the rate table that prices a request step: the model that served the request. A break that a model change caused is priced at the rates of the model after the change (spec §11 question 10, proposed rule), so both sides of the break use one table and the figure is the cache effect alone. The price difference between the two models is the model change's own saving, which the library does not compute (R50).
type End ¶
type End struct {
Thread accountant.Thread `json:"thread"`
Forwarded accountant.Body `json:"forwarded"`
Breakpoints []accountant.Breakpoint `json:"breakpoints"`
Facts Facts `json:"facts"`
}
End is the argument of Request.EndRequest.
type Expected ¶
type Expected struct {
Phase accountant.CachePhase `json:"phase,omitempty"`
// Boundary is asserted only when present. A cold request has B* = 0 and no position to name.
Boundary *accountant.Position `json:"boundary,omitempty"`
// BaselineUsage is what the provider would have billed for the client body with no context
// operation at all (§6.3 conservation). The step's Usage is what it billed with them. Their
// price difference is the sum of Saved minus Caused over Ops. Absent on a standalone step.
BaselineUsage *accountant.Usage `json:"baselineUsage,omitempty"`
// Ops are the priced operations that save or cost something, or carry a Call, in the order
// Compute returns them: reported, then active ones applied again. Operations that price to
// nothing are not listed.
Ops []ExpectedOp `json:"ops"`
// Effects are the cache effects Compute found (breaks, rescues, breakpoint changes), in the
// order it returns them. Only the library writes these, so no step has an input form of them.
Effects []ExpectedEffect `json:"effects,omitempty"`
Unpriced []ExpectedUnpriced `json:"unpriced,omitempty"`
// Checks are the names of the checks (§6.5) that must fail on this step. Absent means none fails.
Checks []string `json:"checks,omitempty"`
// Compaction is the record the library must return for a reported client compaction. It is asserted
// both ways: a step that reports no verdict must get no record.
Compaction *ExpectedCompaction `json:"compaction,omitempty"`
}
Expected is what Compute must return for one step, in tokens for each tier.
type ExpectedCompaction ¶ added in v0.1.1
type ExpectedCompaction struct {
Trigger accountant.CompactionTrigger `json:"trigger"`
Ended []string `json:"ended"`
}
ExpectedCompaction is the Result.Compaction record: the host's verdict and the changes that ended.
type ExpectedEffect ¶
type ExpectedEffect struct {
Note string `json:"note,omitempty"` // for the reader; never asserted
Kind accountant.CacheEffectKind `json:"kind"`
ChangeID string `json:"changeId"`
From *accountant.Position `json:"from,omitempty"`
// FromNil asserts that From is nil, the start of the prompt. A missing "from" asserts nothing.
FromNil bool `json:"fromNil,omitempty"`
To *accountant.Position `json:"to,omitempty"`
TTL string `json:"ttl,omitempty"`
Saved accountant.TierTokens `json:"saved"`
Caused accountant.TierTokens `json:"caused"`
Cause accountant.CacheEffectCause `json:"cause,omitempty"`
// InBaseline marks a break that the client body would have had too (an entry lost early, a client
// edit): it is on the record but cancels out of conservation. A break that an operator left behind
// (its change ended) is not in the baseline, so it counts.
InBaseline bool `json:"inBaseline,omitempty"`
}
ExpectedEffect is one cache effect. Its range is asserted only when present.
func (ExpectedEffect) Counted ¶
func (e ExpectedEffect) Counted() bool
Counted reports whether the effect is part of the bill difference (§6.3).
type ExpectedOp ¶
type ExpectedOp struct {
Note string `json:"note,omitempty"` // for the reader: replay, break, rescue; never asserted
ChangeID string `json:"changeId"`
Saved accountant.TierTokens `json:"saved"`
Caused accountant.TierTokens `json:"caused"`
Call *accountant.ModelCall `json:"call,omitempty"` // a spend: the host prices it
// Estimated is asserted both ways. Every rewrite is converted from bytes (§4.2 rule 7), so it must be
// marked; a spend is priced by the host from the call's own usage, so it must not.
Estimated bool `json:"estimated,omitempty"`
}
ExpectedOp is one priced operation.
type ExpectedUnpriced ¶
ExpectedUnpriced is an operation the library must report as not priced, and why.
type Facts ¶
type Facts struct {
TTL string `json:"ttl"`
Lifetime accountant.LifetimeKind `json:"lifetime"`
LastPing time.Time `json:"lastPing,omitzero"`
PingRead *accountant.Position `json:"pingRead,omitempty"`
PingWindow string `json:"pingWindow,omitempty"`
// PingTTL is the TTL the last ping asked ("5m", "1h"); empty = not known.
PingTTL string `json:"pingTtl,omitempty"`
Provider accountant.Provider `json:"provider,omitzero"`
// MinCacheable is the model's minimum cacheable length in tokens; 0 = not set.
MinCacheable int `json:"minCacheable,omitempty"`
}
Facts is accountant.EntryFacts with a readable TTL ("5m").
func (Facts) EntryFacts ¶
func (f Facts) EntryFacts() accountant.EntryFacts
EntryFacts converts the facts to the library's type. It panics on a malformed TTL, which is a bug in the case file.
type Rate ¶
type Rate struct{ Input, CacheWrite5m, CacheWrite1h, CacheRead, Output int64 }
Rate is a price per million tokens, in micro-dollars.
func (Rate) CallPicos ¶
func (r Rate) CallPicos(u accountant.CallUsage) int64
CallPicos prices everything a call's response bills, output included.
func (Rate) Picos ¶
func (r Rate) Picos(t accountant.TierTokens) int64
Picos prices tokens in pico-dollars (1e-12 USD): tokens × (µ$ per million tokens) is exact, so no figure is rounded until it is shown (testing.md §10.2, "Rounding").
func (Rate) UsagePicos ¶
func (r Rate) UsagePicos(u accountant.Usage) int64
UsagePicos prices a billed prompt usage. CacheWrite1h is a part of CacheWrite.
type Step ¶
type Step struct {
Standalone *accountant.RequestOps `json:"standalone,omitempty"`
Begin *Begin `json:"begin,omitempty"`
Add []accountant.Operation `json:"add,omitempty"` // as the operators reported them; replays are not repeated (§4.6)
End *End `json:"end,omitempty"`
Usage accountant.Usage `json:"usage"`
Expected Expected `json:"expected"`
}
Step is the calls of one request and the Result its Compute must return, or one standalone RequestOps (a keep-alive ping) priced with ComputeStandalone.
func (Step) IsStandalone ¶
IsStandalone reports whether the step is a RequestOps with no request record.