mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Refactors the cached token code for all models
This commit is contained in:
@@ -106,21 +106,21 @@ export class UnboundHandler implements ApiHandler, SingleCompletionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (usage) {
|
if (usage) {
|
||||||
if (this.getModel().id.startsWith("anthropic/")) {
|
const usageData: any = {
|
||||||
yield {
|
type: "usage",
|
||||||
type: "usage",
|
inputTokens: usage?.prompt_tokens || 0,
|
||||||
inputTokens: usage?.prompt_tokens || 0,
|
outputTokens: usage?.completion_tokens || 0,
|
||||||
outputTokens: usage?.completion_tokens || 0,
|
|
||||||
cacheWriteTokens: (usage as any)?.cache_creation_input_tokens || 0,
|
|
||||||
cacheReadTokens: (usage as any)?.cache_read_input_tokens || 0,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
yield {
|
|
||||||
type: "usage",
|
|
||||||
inputTokens: usage?.prompt_tokens || 0,
|
|
||||||
outputTokens: usage?.completion_tokens || 0,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only add cache tokens if they exist
|
||||||
|
if ((usage as any)?.cache_creation_input_tokens) {
|
||||||
|
usageData.cacheWriteTokens = (usage as any).cache_creation_input_tokens
|
||||||
|
}
|
||||||
|
if ((usage as any)?.cache_read_input_tokens) {
|
||||||
|
usageData.cacheReadTokens = (usage as any).cache_read_input_tokens
|
||||||
|
}
|
||||||
|
|
||||||
|
yield usageData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user