Skip to content

Commit fb91836

Browse files
authored
Revert Gemini caching, fix OR supports cache issue (#2918)
1 parent 9b73965 commit fb91836

File tree

20 files changed

+85
-67
lines changed

20 files changed

+85
-67
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Disable Gemini prompt caching

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Roo Code Changelog
22

3+
## [3.14.1] - 2025-04-24
4+
5+
- Disable Gemini caching while we investigate issues reported by the community.
6+
37
## [3.14.0] - 2025-04-23
48

59
- Add prompt caching for `gemini-2.5-pro-preview-03-25` in the Gemini provider (Vertex and OpenRouter coming soon!)

src/api/providers/gemini.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
4040
let cacheWriteTokens: number | undefined = undefined
4141

4242
// https://ai.google.dev/gemini-api/docs/caching?lang=node
43-
if (info.supportsPromptCache && cacheKey) {
44-
const cacheEntry = this.contentCaches.get(cacheKey)
43+
// if (info.supportsPromptCache && cacheKey) {
44+
// const cacheEntry = this.contentCaches.get(cacheKey)
4545

46-
if (cacheEntry) {
47-
uncachedContent = contents.slice(cacheEntry.count, contents.length)
48-
cachedContent = cacheEntry.key
49-
}
46+
// if (cacheEntry) {
47+
// uncachedContent = contents.slice(cacheEntry.count, contents.length)
48+
// cachedContent = cacheEntry.key
49+
// }
5050

51-
const newCacheEntry = await this.client.caches.create({
52-
model,
53-
config: { contents, systemInstruction, ttl: `${CACHE_TTL * 60}s` },
54-
})
51+
// const newCacheEntry = await this.client.caches.create({
52+
// model,
53+
// config: { contents, systemInstruction, ttl: `${CACHE_TTL * 60}s` },
54+
// })
5555

56-
if (newCacheEntry.name) {
57-
this.contentCaches.set(cacheKey, { key: newCacheEntry.name, count: contents.length })
58-
cacheWriteTokens = newCacheEntry.usageMetadata?.totalTokenCount ?? 0
59-
}
60-
}
56+
// if (newCacheEntry.name) {
57+
// this.contentCaches.set(cacheKey, { key: newCacheEntry.name, count: contents.length })
58+
// cacheWriteTokens = newCacheEntry.usageMetadata?.totalTokenCount ?? 0
59+
// }
60+
// }
6161

6262
const params: GenerateContentParameters = {
6363
model,
@@ -94,13 +94,13 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
9494
const cacheReadTokens = lastUsageMetadata.cachedContentTokenCount
9595
const reasoningTokens = lastUsageMetadata.thoughtsTokenCount
9696

97-
const totalCost = this.calculateCost({
98-
info,
99-
inputTokens,
100-
outputTokens,
101-
cacheWriteTokens,
102-
cacheReadTokens,
103-
})
97+
// const totalCost = this.calculateCost({
98+
// info,
99+
// inputTokens,
100+
// outputTokens,
101+
// cacheWriteTokens,
102+
// cacheReadTokens,
103+
// })
104104

105105
yield {
106106
type: "usage",
@@ -109,7 +109,7 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
109109
cacheWriteTokens,
110110
cacheReadTokens,
111111
reasoningTokens,
112-
totalCost,
112+
// totalCost,
113113
}
114114
}
115115
}

src/api/providers/openrouter.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,13 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
8585

8686
// Prompt caching: https://openrouter.ai/docs/prompt-caching
8787
// Now with Gemini support: https://openrouter.ai/docs/features/prompt-caching
88-
if (supportsPromptCache) {
88+
// Note that we don't check the `ModelInfo` object because it is cached
89+
// in the settings for OpenRouter.
90+
if (this.isPromptCacheSupported(modelId)) {
8991
openAiMessages[0] = {
9092
role: "system",
91-
content: [
92-
{
93-
type: "text",
94-
text: systemPrompt,
95-
// @ts-ignore-next-line
96-
cache_control: { type: "ephemeral" },
97-
},
98-
],
93+
// @ts-ignore-next-line
94+
content: [{ type: "text", text: systemPrompt, cache_control: { type: "ephemeral" } }],
9995
}
10096

10197
// Add cache_control to the last two user messages
@@ -108,13 +104,17 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
108104
}
109105

110106
if (Array.isArray(msg.content)) {
111-
// NOTE: this is fine since env details will always be added at the end. but if it weren't there, and the user added a image_url type message, it would pop a text part before it and then move it after to the end.
107+
// NOTE: This is fine since env details will always be added
108+
// at the end. But if it wasn't there, and the user added a
109+
// image_url type message, it would pop a text part before
110+
// it and then move it after to the end.
112111
let lastTextPart = msg.content.filter((part) => part.type === "text").pop()
113112

114113
if (!lastTextPart) {
115114
lastTextPart = { type: "text", text: "..." }
116115
msg.content.push(lastTextPart)
117116
}
117+
118118
// @ts-ignore-next-line
119119
lastTextPart["cache_control"] = { type: "ephemeral" }
120120
}
@@ -227,6 +227,15 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
227227
const completion = response as OpenAI.Chat.ChatCompletion
228228
return completion.choices[0]?.message?.content || ""
229229
}
230+
231+
private isPromptCacheSupported(modelId: string) {
232+
return (
233+
modelId.startsWith("anthropic/claude-3.7-sonnet") ||
234+
modelId.startsWith("anthropic/claude-3.5-sonnet") ||
235+
modelId.startsWith("anthropic/claude-3-opus") ||
236+
modelId.startsWith("anthropic/claude-3-haiku")
237+
)
238+
}
230239
}
231240

232241
export async function getOpenRouterModels(options?: ApiHandlerOptions) {
@@ -250,7 +259,7 @@ export async function getOpenRouterModels(options?: ApiHandlerOptions) {
250259
thinking: rawModel.id === "anthropic/claude-3.7-sonnet:thinking",
251260
}
252261

253-
// NOTE: this needs to be synced with api.ts/openrouter default model info.
262+
// NOTE: This needs to be synced with api.ts/openrouter default model info.
254263
switch (true) {
255264
case rawModel.id.startsWith("anthropic/claude-3.7-sonnet"):
256265
modelInfo.supportsComputerUse = true

src/shared/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ export const geminiModels = {
682682
maxTokens: 65_535,
683683
contextWindow: 1_048_576,
684684
supportsImages: true,
685-
supportsPromptCache: true,
685+
supportsPromptCache: false,
686686
inputPrice: 2.5, // This is the pricing for prompts above 200k tokens.
687687
outputPrice: 15,
688688
cacheReadsPrice: 0.625,
@@ -706,7 +706,7 @@ export const geminiModels = {
706706
maxTokens: 8192,
707707
contextWindow: 1_048_576,
708708
supportsImages: true,
709-
supportsPromptCache: true,
709+
supportsPromptCache: false,
710710
inputPrice: 0.1,
711711
outputPrice: 0.4,
712712
cacheReadsPrice: 0.025,
@@ -756,7 +756,7 @@ export const geminiModels = {
756756
maxTokens: 8192,
757757
contextWindow: 1_048_576,
758758
supportsImages: true,
759-
supportsPromptCache: true,
759+
supportsPromptCache: false,
760760
inputPrice: 0.15, // This is the pricing for prompts above 128k tokens.
761761
outputPrice: 0.6,
762762
cacheReadsPrice: 0.0375,

webview-ui/src/i18n/locales/ca/chat.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@
189189
"title": "🎉 Roo Code 3.14 publicat",
190190
"description": "Roo Code 3.14 porta noves funcionalitats i millores basades en els teus comentaris.",
191191
"whatsNew": "Novetats",
192-
"feature1": "<bold>Memòria cau per a Gemini 2.5 Pro</bold>: <code>gemini-2.5-pro-preview-03-25</code> ara suporta memòria cau de prompts al proveïdor Gemini (Vertex i OpenRouter disponibles aviat)",
193-
"feature2": "<bold>Eines d'edició millorades</bold>: Les eines <code>search_and_replace</code> i <code>insert_content</code> han estat millorades i ja no són experimentals",
192+
"feature1": "<bold>Eines d'edició millorades</bold>: Les eines <code>search_and_replace</code> i <code>insert_content</code> han estat millorades i ja no són experimentals",
193+
"feature2": "<bold>Millores a apply_diff</bold>: Continuem treballant per millorar l'eina <code>apply_diff</code>",
194194
"feature3": "<bold>Moltes altres millores</bold>: Nombroses correccions i optimitzacions a tota l'extensió",
195195
"hideButton": "Amagar anunci",
196196
"detailsDiscussLinks": "Obtingues més detalls i participa a <discordLink>Discord</discordLink> i <redditLink>Reddit</redditLink> 🚀"

webview-ui/src/i18n/locales/de/chat.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@
189189
"title": "🎉 Roo Code 3.14 veröffentlicht",
190190
"description": "Roo Code 3.14 bringt neue Funktionen und Verbesserungen basierend auf deinem Feedback.",
191191
"whatsNew": "Was ist neu",
192-
"feature1": "<bold>Gemini 2.5 Pro Caching</bold>: <code>gemini-2.5-pro-preview-03-25</code> unterstützt jetzt Prompt-Caching im Gemini-Provider (Vertex und OpenRouter folgen bald)",
193-
"feature2": "<bold>Verbesserte Bearbeitungswerkzeuge</bold>: Die <code>search_and_replace</code> und <code>insert_content</code> Tools wurden verbessert und sind nicht mehr experimentell",
192+
"feature1": "<bold>Verbesserte Bearbeitungswerkzeuge</bold>: Die <code>search_and_replace</code> und <code>insert_content</code> Tools wurden verbessert und sind nicht mehr experimentell",
193+
"feature2": "<bold>Diff Apply Fixes</bold>: Wir arbeiten weiterhin an der Verbesserung des <code>apply_diff</code> Tools",
194194
"feature3": "<bold>Zahlreiche andere Verbesserungen</bold>: Viele Fehlerbehebungen und Optimierungen in der gesamten Erweiterung",
195195
"hideButton": "Ankündigung ausblenden",
196196
"detailsDiscussLinks": "Erhalte mehr Details und diskutiere auf <discordLink>Discord</discordLink> und <redditLink>Reddit</redditLink> 🚀"

webview-ui/src/i18n/locales/en/chat.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@
182182
"title": "🎉 Roo Code 3.14 Released",
183183
"description": "Roo Code 3.14 brings new features and improvements based on your feedback.",
184184
"whatsNew": "What's New",
185-
"feature1": "<bold>Gemini 2.5 Pro Caching</bold>: <code>gemini-2.5-pro-preview-03-25</code> now supports prompt caching in the Gemini provider (Vertex and OpenRouter coming soon)",
186-
"feature2": "<bold>Improved Editing Tools</bold>: The <code>search_and_replace</code> and <code>insert_content</code> tools have been improved and graduated from experimental status",
185+
"feature1": "<bold>Improved Editing Tools</bold>: The <code>search_and_replace</code> and <code>insert_content</code> tools have been improved and graduated from experimental status",
186+
"feature2": "<bold>Diff Apply Fixes</bold>: We continue to work on improving the <code>apply_diff</code> tool",
187187
"feature3": "<bold>Tons of Other Improvements</bold>: Numerous fixes and enhancements throughout the extension",
188188
"hideButton": "Hide announcement",
189189
"detailsDiscussLinks": "Get more details and discuss in <discordLink>Discord</discordLink> and <redditLink>Reddit</redditLink> 🚀"

webview-ui/src/i18n/locales/es/chat.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@
189189
"title": "🎉 Roo Code 3.14 publicado",
190190
"description": "Roo Code 3.14 trae nuevas funcionalidades y mejoras basadas en tus comentarios.",
191191
"whatsNew": "Novedades",
192-
"feature1": "<bold>Caché para Gemini 2.5 Pro</bold>: <code>gemini-2.5-pro-preview-03-25</code> ahora admite caché de prompts en el proveedor Gemini (Vertex y OpenRouter próximamente)",
193-
"feature2": "<bold>Herramientas de edición mejoradas</bold>: Las herramientas <code>search_and_replace</code> y <code>insert_content</code> han sido mejoradas y ya no son experimentales",
192+
"feature1": "<bold>Herramientas de edición mejoradas</bold>: Las herramientas <code>search_and_replace</code> y <code>insert_content</code> han sido mejoradas y ya no son experimentales",
193+
"feature2": "<bold>Mejoras en apply_diff</bold>: Continuamos trabajando en mejorar la herramienta <code>apply_diff</code>",
194194
"feature3": "<bold>Montones de otras mejoras</bold>: Numerosas correcciones y mejoras en toda la extensión",
195195
"hideButton": "Ocultar anuncio",
196196
"detailsDiscussLinks": "Obtén más detalles y participa en <discordLink>Discord</discordLink> y <redditLink>Reddit</redditLink> 🚀"

webview-ui/src/i18n/locales/fr/chat.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@
189189
"title": "🎉 Roo Code 3.14 est sortie",
190190
"description": "Roo Code 3.14 apporte de nouvelles fonctionnalités et améliorations basées sur vos retours.",
191191
"whatsNew": "Quoi de neuf",
192-
"feature1": "<bold>Cache pour Gemini 2.5 Pro</bold> : <code>gemini-2.5-pro-preview-03-25</code> prend maintenant en charge le cache des prompts dans le fournisseur Gemini (Vertex et OpenRouter bientôt disponibles)",
193-
"feature2": "<bold>Outils d'édition améliorés</bold> : Les outils <code>search_and_replace</code> et <code>insert_content</code> ont été améliorés et ne sont plus expérimentaux",
192+
"feature1": "<bold>Outils d'édition améliorés</bold> : Les outils <code>search_and_replace</code> et <code>insert_content</code> ont été améliorés et ne sont plus expérimentaux",
193+
"feature2": "<bold>Corrections pour apply_diff</bold> : Nous continuons à travailler sur l'amélioration de l'outil <code>apply_diff</code>",
194194
"feature3": "<bold>Quantité d'autres améliorations</bold> : Nombreuses corrections et optimisations dans toute l'extension",
195195
"hideButton": "Masquer l'annonce",
196196
"detailsDiscussLinks": "Obtenez plus de détails et participez aux discussions sur <discordLink>Discord</discordLink> et <redditLink>Reddit</redditLink> 🚀"

0 commit comments

Comments
 (0)