Files
Daniel Hiltgen 855f4bf989 Report cached prompt tokens (#17943)
* Report cached prompt tokens

Add prompt_eval_cached_count to native responses and expose equivalent cached-token fields through the OpenAI- and Anthropic-compatible APIs. Keep prompt_eval_count as the logical input total while excluding cache hits from CLI and benchmark prefill rates. Surface processed and cached prompt counts in benchmark output.

Collect cache counts from llama-server and MLX, preserve coherent metrics across two-pass structured generation.

Fixes #8008

Related to #15758

* review comments
2026-09-02 09:30:44 -07:00

25 lines
406 B
Go

package middleware
func optionalIntValue(v *int) int {
if v == nil {
return 0
}
return *v
}
func addOptionalInts(a, b *int) *int {
if a == nil && b == nil {
return nil
}
value := optionalIntValue(a) + optionalIntValue(b)
return &value
}
func maxOptionalInts(a, b *int) *int {
if a == nil && b == nil {
return nil
}
value := max(optionalIntValue(a), optionalIntValue(b))
return &value
}