Skip to content

Commit 81d319f

Browse files
committed
Add extended prompt caching support for OpenAI providers
- rename 'extended cache for anthropic' to simpler 'extended cache' - similarly to anthropic, implement extended cache for openai [Website] - check if open ai extended ttl is correctly set for code at cursor - 'search files by intelligent' should never use extended ttl └── apps └── editor ├── package.json └── src ├── commands │ └── code-at-cursor-command │ └── utils │ └── perform-code-at-cursor.ts ├── constants │ └── providers.ts ├── features │ └── search-files │ └── utils │ └── search-files-by-intelligent.ts ├── services │ ├── prompt-view-api-calls-manager.ts │ └── providers-manager.ts ├── utils │ ├── build-user-content.ts │ └── send-llm-message.ts └── views ├── prompt │ └── backend │ └── message-handlers │ └── handle-make-api-call.ts └── settings ├── backend │ └── message-handlers │ ├── handle-get-providers.ts │ └── handle-update-provider.ts ├── frontend │ ├── forms │ │ └── EditProviderForm │ │ └── EditProviderForm.tsx │ ├── hooks │ │ └── use-provider-editing.ts │ └── i18n │ └── translations │ └── edit-provider-form.ts └── types └── messages.ts
1 parent ac3e080 commit 81d319f

6 files changed

Lines changed: 69 additions & 43 deletions

File tree

‎apps/editor/src/commands/code-at-cursor-command/utils/perform-code-at-cursor.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from '@/constants/state-keys'
3232
import { show_incomplete_setup_warning } from '@/utils/show-missing-configuration-notification'
3333
import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
34+
import { PROVIDERS } from '../../../constants/providers'
3435

3536
export const perform_code_at_cursor = async (params: {
3637
workspace_provider: WorkspaceProvider
@@ -538,6 +539,14 @@ export const perform_code_at_cursor = async (params: {
538539
model: code_at_cursor_api_configuration.model
539540
}
540541

542+
const is_openai = provider.base_url == PROVIDERS.OpenAI.base_url
543+
if (is_openai) {
544+
body.prompt_cache_options = { mode: 'explicit' }
545+
if (provider.extended_cache) {
546+
body.prompt_cache_options.ttl = '12h'
547+
}
548+
}
549+
541550
apply_reasoning_effort({
542551
body,
543552
provider,

‎apps/editor/src/features/search-files/utils/search-files-by-intelligent.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Logger } from '@shared/utils/logger'
99
import { FileData } from './analyze-files'
1010
import { Provider } from '@/services/providers-manager'
1111
import { t } from '@/i18n'
12+
import { PROVIDERS } from '@/constants/providers'
1213

1314
export const search_files_by_intelligent = async (
1415
files_data: FileData[],
@@ -33,7 +34,7 @@ export const search_files_by_intelligent = async (
3334
const part1 = `# Files\n\n${md_files}`
3435
const part2 = `# Task\n\n${base_instructions}\n\n# Output formatting\n\n${ai_file_search_format_instructions}\n\n# Query\n\n${instructions}`
3536
const user_content = build_user_content({
36-
provider,
37+
provider: { ...provider, extended_cache: false },
3738
part1,
3839
part2
3940
})
@@ -44,6 +45,11 @@ export const search_files_by_intelligent = async (
4445
model: selected_config.model
4546
}
4647

48+
const is_openai = provider.base_url == PROVIDERS.OpenAI.base_url
49+
if (is_openai) {
50+
body.prompt_cache_options = { mode: 'explicit' }
51+
}
52+
4753
apply_reasoning_effort({
4854
body,
4955
provider,

‎apps/editor/src/utils/build-user-content.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export const build_user_content = (params: {
4343
}
4444
} else if (is_openai) {
4545
cache_config.prompt_cache_breakpoint = { mode: 'explicit' }
46+
if (params.provider.extended_cache) {
47+
cache_config.prompt_cache_breakpoint.ttl = '12h'
48+
}
4649
}
4750

4851
const user_content: any[] = [

‎apps/editor/src/views/prompt/backend/message-handlers/handle-make-api-call.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ export const handle_make_api_call = async (
143143
const is_openai = provider.base_url == PROVIDERS.OpenAI.base_url
144144
if (is_openai) {
145145
body.prompt_cache_options = { mode: 'explicit' }
146+
if (provider.extended_cache) {
147+
body.prompt_cache_options.ttl = '12h'
148+
}
146149
}
147150

148151
apply_reasoning_effort({

‎apps/editor/src/views/settings/frontend/forms/EditProviderForm/EditProviderForm.tsx‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,21 @@ export const EditProviderForm: React.FC<Props> = (props) => {
102102
/>
103103
</UiField>
104104

105-
{base_url.includes('api.anthropic.com') && (
105+
{(base_url.includes('api.anthropic.com') ||
106+
base_url.includes('api.openai.com')) && (
106107
<UiField
107-
label={t('edit-provider-form.extended-cache.anthropic.title')}
108+
label={t('edit-provider-form.extended-cache.title')}
108109
info={
109110
<>
110-
{t('edit-provider-form.extended-cache.anthropic.description')}{' '}
111-
<a href="https://platform.claude.com/docs/en/build-with-claude/prompt-caching#ttl-support">
112-
{t(
113-
'edit-provider-form.extended-cache.anthropic.learn-more'
114-
)}
111+
{t('edit-provider-form.extended-cache.description')}{' '}
112+
<a
113+
href={
114+
base_url.includes('api.anthropic.com')
115+
? 'https://platform.claude.com/docs/en/build-with-claude/prompt-caching#ttl-support'
116+
: 'https://developers.openai.com/api/docs/guides/prompt-caching#cache-lifetime'
117+
}
118+
>
119+
{t('edit-provider-form.extended-cache.learn-more')}
115120
</a>
116121
</>
117122
}

‎apps/editor/src/views/settings/frontend/i18n/translations/edit-provider-form.ts‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -107,44 +107,44 @@ export const translations = {
107107
hu: 'Adja meg az API Kulcsot',
108108
bg: 'Въведете API ключ'
109109
},
110-
'edit-provider-form.extended-cache.anthropic.title': {
111-
en: 'Extended Cache for Anthropic',
112-
pl: 'Rozszerzona pamięć podręczna dla Anthropic',
113-
'zh-cn': 'Anthropic 的扩展缓存',
114-
ja: 'Anthropic の拡張キャッシュ',
115-
'zh-tw': 'Anthropic 的擴展快取',
116-
de: 'Erweiterter Cache für Anthropic',
117-
es: 'Caché extendido para Anthropic',
118-
fr: 'Cache étendu pour Anthropic',
119-
'pt-br': 'Cache Estendido para Anthropic',
120-
ru: 'Расширенный кэш для Anthropic',
121-
ko: 'Anthropic용 확장 캐시',
122-
it: 'Cache estesa per Anthropic',
123-
tr: 'Anthropic için Genişletilmiş Önbellek',
124-
cs: 'Rozšířená mezipaměť pro Anthropic',
125-
hu: 'Bővített gyorsítótár Anthropic-hoz',
126-
bg: 'Разширен кеш за Anthropic'
110+
'edit-provider-form.extended-cache.title': {
111+
en: 'Extended Cache',
112+
pl: 'Rozszerzone przechowywanie w cache',
113+
'zh-cn': '扩展缓存',
114+
ja: '拡張キャッシュ',
115+
'zh-tw': '擴充快取',
116+
de: 'Erweiterter Cache',
117+
es: 'Caché extendida',
118+
fr: 'Cache étendu',
119+
'pt-br': 'Cache Estendido',
120+
ru: 'Расширенный кэш',
121+
ko: '확장 캐시',
122+
it: 'Cache estesa',
123+
tr: 'Genişletilmiş Önbellek',
124+
cs: 'Rozšířená mezipaměť',
125+
hu: 'Bővített gyorsítótár',
126+
bg: 'Разширен кеш'
127127
},
128-
'edit-provider-form.extended-cache.anthropic.description': {
129-
en: 'Enable 1-hour prompt caching for requests including the selected files.',
130-
pl: 'Włącz 1-godzinne buforowanie promptów dla zapytań zawierających wybrane pliki.',
131-
'zh-cn': '为包含所选文件的请求启用 1 小时提示词缓存。',
132-
ja: '選択されたファイルを含むリクエストに対して、1時間のプロンプトキャッシュを有効にします。',
133-
'zh-tw': '為包含所選檔案的請求啟用 1 小時提示詞快取。',
134-
de: 'Aktivieren Sie das 1-stündige Prompt-Caching für Anfragen, die die ausgewählten Dateien enthalten.',
135-
es: 'Habilita el almacenamiento en caché de prompts de 1 hora para las solicitudes que incluyan los archivos seleccionados.',
136-
fr: 'Activez la mise en cache des prompts pendant 1 heure pour les requêtes incluant les fichiers sélectionnés.',
128+
'edit-provider-form.extended-cache.description': {
129+
en: 'Enable extended prompt caching for requests including the selected files.',
130+
pl: 'Włącz rozszerzone buforowanie promptów dla zapytań zawierających wybrane pliki.',
131+
'zh-cn': '为包含所选文件的请求启用扩展提示词缓存。',
132+
ja: '選択されたファイルを含むリクエストに対して、拡張プロンプトキャッシュを有効にします。',
133+
'zh-tw': '為包含所選檔案的請求啟用擴充提示詞快取。',
134+
de: 'Aktivieren Sie erweitertes Prompt-Caching für Anfragen, die die ausgewählten Dateien enthalten.',
135+
es: 'Habilita el almacenamiento en caché extendido de prompts para las solicitudes que incluyan los archivos seleccionados.',
136+
fr: 'Activez la mise en cache étendue des prompts pour les requêtes incluant les fichiers sélectionnés.',
137137
'pt-br':
138-
'Ative o cache de prompts de 1 hora para requisições que incluam os arquivos selecionados.',
139-
ru: 'Включить 1-часовое кэширование промптов для запросов, включающих выбранные файлы.',
140-
ko: '선택한 파일이 포함된 요청에 대해 1시간 프롬프트 캐싱을 활성화합니다.',
141-
it: 'Abilita la cache dei prompt di 1 ora per le richieste che includono i file selezionati.',
142-
tr: 'Seçili dosyaları içeren istekler için 1 saatlik istem önbelleğe almayı etkinleştirin.',
143-
cs: 'Povolit 1hodinové ukládání promptů do mezipaměti pro požadavky obsahující vybrané soubory.',
144-
hu: 'Engedélyezze az 1 órás prompt gyorsítótárazást a kiválasztott fájlokat tartalmazó kérésekhez.',
145-
bg: 'Включете 1-часово кеширане на промптове за заявки, включващи избраните файлове.'
138+
'Ative o cache estendido de prompts para requisições que incluam os arquivos selecionados.',
139+
ru: 'Включить расширенное кэширование промптов для запросов, включающих выбранные файлы.',
140+
ko: '선택한 파일이 포함된 요청에 대해 확장 프롬프트 캐싱을 활성화합니다.',
141+
it: 'Abilita la cache estesa dei prompt per le richieste che includono i file selezionati.',
142+
tr: 'Seçili dosyaları içeren istekler için genişletilmiş istem önbelleğe almayı etkinleştirin.',
143+
cs: 'Povolit rozšířené ukládání promptů do mezipaměti pro požadavky obsahující vybrané soubory.',
144+
hu: 'Engedélyezze a bővített prompt gyorsítótárazást a kiválasztott fájlokat tartalmazó kérésekhez.',
145+
bg: 'Включете разширено кеширане на промптове за заявки, включващи избраните файлове.'
146146
},
147-
'edit-provider-form.extended-cache.anthropic.learn-more': {
147+
'edit-provider-form.extended-cache.learn-more': {
148148
en: 'Learn more',
149149
pl: 'Dowiedz się więcej',
150150
'zh-cn': '了解更多',

0 commit comments

Comments
 (0)