Aggregate reasoning usage and derive cache hit ratios
This commit is contained in:
@@ -101,6 +101,16 @@ type ObservedTokenUsage struct {
|
||||
CacheWriteTokens ObservedTokenCount
|
||||
}
|
||||
|
||||
// CacheHitRatio returns the fraction of input tokens served from cache when
|
||||
// both counts are known, complete, and consistent. Cache writes are independent.
|
||||
func (u ObservedTokenUsage) CacheHitRatio() (float64, bool) {
|
||||
input, reads := u.PromptTokens, u.CachedTokens
|
||||
if !input.Known || !input.Complete || !reads.Known || !reads.Complete || input.Value <= 0 || reads.Value < 0 || reads.Value > input.Value {
|
||||
return 0, false
|
||||
}
|
||||
return float64(reads.Value) / float64(input.Value), true
|
||||
}
|
||||
|
||||
// ExecutionEvent contains metadata only, not provider text, request content,
|
||||
// credentials, URLs, headers, or error objects. It has no stable JSON contract.
|
||||
// Identifiers themselves may be sensitive. Nonterminal aggregate counters are
|
||||
|
||||
Reference in New Issue
Block a user