feat: estimate and populate prompt cache tokens when upstream omits breakdown

This commit is contained in:
Luxferre
2026-08-27 14:42:44 +03:00
parent c856595199
commit 04d83a6b7c
2 changed files with 46 additions and 2 deletions
+18
View File
@@ -192,3 +192,21 @@ func TestStreamerUsage(t *testing.T) {
}
}
func TestResolveCachedTokens(t *testing.T) {
// If upstream explicitly provides cached tokens (>0), preserve it
if got := ResolveCachedTokens(500, 1000, "hello"); got != 500 {
t.Fatalf("expected 500, got %d", got)
}
// If upstream returns 0, estimate based on promptTokens and current question
if got := ResolveCachedTokens(0, 1397, "Say hello in 1 word"); got <= 0 || got >= 1397 {
t.Fatalf("expected cached tokens between 1 and 1396, got %d", got)
}
// If promptTokens <= 0, return 0
if got := ResolveCachedTokens(0, 0, "hello"); got != 0 {
t.Fatalf("expected 0, got %d", got)
}
}