Defaulting to -1 rather than boolean false

53976143470dce5e1e11166c81c37e04cd3cbfbe

Honey Tree <kalakanlogs@proton.me>

2 files changed, +9 -4Ignore whitespace
default/config.yaml+2 -1
@@ -174,6 +174,7 @@ claude:
174174 # Use with caution. Behavior may be unpredictable and no guarantees can or will be made.
175175 # Set to an integer to specify the desired depth. 0 (which does NOT include the prefill)
176176 # should be ideal for most use cases.
177- cachingAtDepth: false
177+ # Any value other than a non-negative integer will be ignored and caching at depth will not be enabled.
178+ cachingAtDepth: -1
178179# -- SERVER PLUGIN CONFIGURATION --
179180enableServerPlugins: false
src/endpoints/backends/chat-completions.js+7 -3
@@ -80,7 +80,11 @@ async function sendClaudeRequest(request, response) {
8080 const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.CLAUDE);
8181 const divider = '-'.repeat(process.stdout.columns);
8282 const enableSystemPromptCache = getConfigValue('claude.enableSystemPromptCache', false) && request.body.model.startsWith('claude-3');
8383 let cachingAtDepth = getConfigValue('claude.cachingAtDepth', false-1) && request.body.model.startsWith('claude-3');
84+ // Disabled if not an integer or negative
85+ if (!Number.isInteger(cachingAtDepth) || cachingAtDepth < 0) {
86+ cachingAtDepth = -1;
87+ }
8488
8589 if (!apiKey) {
8690 console.log(color.red(`Claude API key is missing.\n${divider}`));
@@ -140,7 +144,7 @@ async function sendClaudeRequest(request, response) {
140144 }
141145 }
142146
143147 if (cachingAtDepth !== false-1) {
144148 // There are extremely few scenarios in which caching the prefill is a good idea, it mostly just breaks everything
145149 const messageCount = convertedPrompt.messages.length;
146150 cachingAtDepth += convertedPrompt.messages[messageCount - 1].role === 'assistant' ? 1 : 0;
@@ -156,7 +160,7 @@ async function sendClaudeRequest(request, response) {
156160 }
157161 }
158162
159163 if (enableSystemPromptCache || cachingAtDepth !== false-1) {
160164 additionalHeaders['anthropic-beta'] = 'prompt-caching-2024-07-31';
161165 }
162166