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:
174 # Use with caution. Behavior may be unpredictable and no guarantees can or will be made.174 # Use with caution. Behavior may be unpredictable and no guarantees can or will be made.
175 # Set to an integer to specify the desired depth. 0 (which does NOT include the prefill)175 # Set to an integer to specify the desired depth. 0 (which does NOT include the prefill)
176 # should be ideal for most use cases.176 # should be ideal for most use cases.
177 cachingAtDepth: false177 # Any value other than a non-negative integer will be ignored and caching at depth will not be enabled.
178 cachingAtDepth: -1
178# -- SERVER PLUGIN CONFIGURATION --179# -- SERVER PLUGIN CONFIGURATION --
179enableServerPlugins: false180enableServerPlugins: false
src/endpoints/backends/chat-completions.js+7 -3
@@ -80,7 +80,11 @@ async function sendClaudeRequest(request, response) {
80 const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.CLAUDE);80 const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.CLAUDE);
81 const divider = '-'.repeat(process.stdout.columns);81 const divider = '-'.repeat(process.stdout.columns);
82 const enableSystemPromptCache = getConfigValue('claude.enableSystemPromptCache', false) && request.body.model.startsWith('claude-3');82 const enableSystemPromptCache = getConfigValue('claude.enableSystemPromptCache', false) && request.body.model.startsWith('claude-3');
83 let cachingAtDepth = getConfigValue('claude.cachingAtDepth', false) && request.body.model.startsWith('claude-3');83 let cachingAtDepth = getConfigValue('claude.cachingAtDepth', -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
85 if (!apiKey) {89 if (!apiKey) {
86 console.log(color.red(`Claude API key is missing.\n${divider}`));90 console.log(color.red(`Claude API key is missing.\n${divider}`));
@@ -140,7 +144,7 @@ async function sendClaudeRequest(request, response) {
140 }144 }
141 }145 }
142146
143 if (cachingAtDepth !== false) {147 if (cachingAtDepth !== -1) {
144 // There are extremely few scenarios in which caching the prefill is a good idea, it mostly just breaks everything148 // There are extremely few scenarios in which caching the prefill is a good idea, it mostly just breaks everything
145 const messageCount = convertedPrompt.messages.length;149 const messageCount = convertedPrompt.messages.length;
146 cachingAtDepth += convertedPrompt.messages[messageCount - 1].role === 'assistant' ? 1 : 0;150 cachingAtDepth += convertedPrompt.messages[messageCount - 1].role === 'assistant' ? 1 : 0;
@@ -156,7 +160,7 @@ async function sendClaudeRequest(request, response) {
156 }160 }
157 }161 }
158162
159 if (enableSystemPromptCache || cachingAtDepth !== false) {163 if (enableSystemPromptCache || cachingAtDepth !== -1) {
160 additionalHeaders['anthropic-beta'] = 'prompt-caching-2024-07-31';164 additionalHeaders['anthropic-beta'] = 'prompt-caching-2024-07-31';
161 }165 }
162166