feat: estimate and populate prompt cache tokens when upstream omits breakdown
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user