feat(llm): add prompt-cache observability and wiki cache-friendly prompts
Normalize provider-specific cache counters into TokenUsage, propagate call purpose and prefix fingerprints through context for logging and Langfuse, and restructure wiki page-modify prompts with warmup/singleflight to improve prefix cache hit rates during reduce batches.
This commit is contained in:
@@ -14,7 +14,10 @@ func logUsage(ctx context.Context, model string, u *types.TokenUsage) {
|
||||
if u == nil {
|
||||
return
|
||||
}
|
||||
purpose, prefixFingerprint := types.LLMCallMetadataFromContext(ctx)
|
||||
logger.Infof(ctx,
|
||||
"[LLM Usage] model=%s, prompt_tokens=%d, completion_tokens=%d, total_tokens=%d, cached_tokens=%d",
|
||||
model, u.PromptTokens, u.CompletionTokens, u.TotalTokens, u.CachedTokens)
|
||||
"[LLM Usage] model=%s, purpose=%s, prompt_prefix=%s, prompt_tokens=%d, completion_tokens=%d, total_tokens=%d, cached_tokens=%d, cache_read_tokens=%d, cache_write_tokens=%d, cache_miss_tokens=%d, cache_reported=%t, cache_status=%s",
|
||||
model, purpose, prefixFingerprint, u.PromptTokens, u.CompletionTokens, u.TotalTokens,
|
||||
u.CachedTokens, u.CacheReadTokens, u.CacheWriteTokens, u.CacheMissTokens,
|
||||
u.CacheReported, u.CacheStatus)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user