fix(engine): align computeCacheHitRatio JSDoc with stored tokenUsage format
This commit is contained in:
@@ -92,15 +92,13 @@ export async function accumulateSessionTokenUsage(
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the cache hit ratio: the fraction of effective input tokens served
|
||||
* from cache. Returns a number in [0, 1]. Useful for measuring the
|
||||
* effectiveness of prompt caching optimizations.
|
||||
* Compute the cache hit ratio: `cachedTokens / (inputTokens + cachedTokens)`.
|
||||
* Returns a number in [0, 1], or 0 when both arguments are 0.
|
||||
*
|
||||
* @param inputTokens - Non-cached input tokens (NOT including cache-write tokens;
|
||||
* use only `tokens.input` here, not `tokens.input + tokens.cacheWrite`)
|
||||
* @param cachedTokens - Tokens read from cache (`tokens.cacheRead`)
|
||||
* @returns Cache hit ratio in [0, 1] matching Anthropic console's `cache_read / input` metric,
|
||||
* or 0 if no tokens used
|
||||
* Compatible with stored `task.tokenUsage` fields: pass `inputTokens` (which
|
||||
* includes cache-write tokens per `accumulateSessionTokenUsage`) and
|
||||
* `cachedTokens` (cache-read tokens). Note this differs slightly from the
|
||||
* Anthropic console metric, which excludes cache-write from the denominator.
|
||||
*/
|
||||
export function computeCacheHitRatio(
|
||||
inputTokens: number,
|
||||
|
||||
Reference in New Issue
Block a user