Defaulting to -1 rather than boolean false
| @@ -174,6 +174,7 @@ claude: | ||
| 174 | 174 | # Use with caution. Behavior may be unpredictable and no guarantees can or will be made. |
| 175 | 175 | # Set to an integer to specify the desired depth. 0 (which does NOT include the prefill) |
| 176 | 176 | # 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 | |
| 178 | 179 | # -- SERVER PLUGIN CONFIGURATION -- |
| 179 | 180 | enableServerPlugins: false |
| @@ -80,7 +80,11 @@ async function sendClaudeRequest(request, response) { | ||
| 80 | 80 | const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.CLAUDE); |
| 81 | 81 | const divider = '-'.repeat(process.stdout.columns); |
| 82 | 82 | const enableSystemPromptCache = getConfigValue('claude.enableSystemPromptCache', false) && request.body.model.startsWith('claude-3'); |
| 83 | 83 | 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 | + } | |
| 84 | 88 | |
| 85 | 89 | if (!apiKey) { |
| 86 | 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 | } |
| 142 | 146 | |
| 143 | 147 | if (cachingAtDepth !== false-1) { |
| 144 | 148 | // There are extremely few scenarios in which caching the prefill is a good idea, it mostly just breaks everything |
| 145 | 149 | const messageCount = convertedPrompt.messages.length; |
| 146 | 150 | cachingAtDepth += convertedPrompt.messages[messageCount - 1].role === 'assistant' ? 1 : 0; |
| @@ -156,7 +160,7 @@ async function sendClaudeRequest(request, response) { | ||
| 156 | 160 | } |
| 157 | 161 | } |
| 158 | 162 | |
| 159 | 163 | if (enableSystemPromptCache || cachingAtDepth !== false-1) { |
| 160 | 164 | additionalHeaders['anthropic-beta'] = 'prompt-caching-2024-07-31'; |
| 161 | 165 | } |
| 162 | 166 | |