mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-09 22:31:08 +00:00
Fix caching logic in Roo provider (#8860)
This commit is contained in:
parent
bd1f890589
commit
b92a22b0c1
2 changed files with 20 additions and 10 deletions
|
|
@ -598,7 +598,12 @@ export const getApiProtocol = (provider: ProviderName | undefined, modelId?: str
|
|||
}
|
||||
|
||||
// Vercel AI Gateway uses anthropic protocol for anthropic models.
|
||||
if (provider && provider === "vercel-ai-gateway" && modelId && modelId.toLowerCase().startsWith("anthropic/")) {
|
||||
if (
|
||||
provider &&
|
||||
["vercel-ai-gateway", "roo"].includes(provider) &&
|
||||
modelId &&
|
||||
modelId.toLowerCase().startsWith("anthropic/")
|
||||
) {
|
||||
return "anthropic"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
|
|||
metadata?.taskId ? { headers: { "X-Roo-Task-ID": metadata.taskId } } : undefined,
|
||||
)
|
||||
|
||||
let lastUsage: RooUsage | undefined = undefined
|
||||
|
||||
for await (const chunk of stream) {
|
||||
const delta = chunk.choices[0]?.delta
|
||||
|
||||
|
|
@ -110,15 +112,18 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
|
|||
}
|
||||
|
||||
if (chunk.usage) {
|
||||
const usage = chunk.usage as RooUsage
|
||||
yield {
|
||||
type: "usage",
|
||||
inputTokens: usage.prompt_tokens || 0,
|
||||
outputTokens: usage.completion_tokens || 0,
|
||||
cacheWriteTokens: usage.cache_creation_input_tokens,
|
||||
cacheReadTokens: usage.prompt_tokens_details?.cached_tokens,
|
||||
totalCost: usage.cost ?? 0,
|
||||
}
|
||||
lastUsage = chunk.usage as RooUsage
|
||||
}
|
||||
}
|
||||
|
||||
if (lastUsage) {
|
||||
yield {
|
||||
type: "usage",
|
||||
inputTokens: lastUsage.prompt_tokens || 0,
|
||||
outputTokens: lastUsage.completion_tokens || 0,
|
||||
cacheWriteTokens: lastUsage.cache_creation_input_tokens,
|
||||
cacheReadTokens: lastUsage.prompt_tokens_details?.cached_tokens,
|
||||
totalCost: lastUsage.cost ?? 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue