Claude: fix prefill tool calling hack with at-depth caching
| @@ -474,6 +474,8 @@ label[for="trim_spaces"]:has(input:checked) i.warning { | ||
| 474 | 474 | |
| 475 | 475 | #claude_function_prefill_warning { |
| 476 | 476 | display: none; |
| 477 | + color: red; | |
| 478 | + font-weight: bold; | |
| 477 | 479 | } |
| 478 | 480 | |
| 479 | 481 | #openai_settings:has(#openai_function_calling:checked):has(#claude_assistant_prefill:not(:placeholder-shown), #claude_assistant_impersonation:not(:placeholder-shown)) #claude_function_prefill_warning { |
| @@ -130,10 +130,6 @@ async function sendClaudeRequest(request, response) { | ||
| 130 | 130 | delete requestBody.system; |
| 131 | 131 | } |
| 132 | 132 | if (useTools) { |
| 133 | - // Claude doesn't do prefills on function calls, and doesn't allow empty messages | |
| 134 | - if (convertedPrompt.messages.length && convertedPrompt.messages[convertedPrompt.messages.length - 1].role === 'assistant') { | |
| 135 | - convertedPrompt.messages.push({ role: 'user', content: '.' }); | |
| 136 | - } | |
| 137 | 133 | additionalHeaders['anthropic-beta'] = 'tools-2024-05-16'; |
| 138 | 134 | requestBody.tool_choice = { type: request.body.tool_choice }; |
| 139 | 135 | requestBody.tools = request.body.tools |
| @@ -141,6 +137,10 @@ async function sendClaudeRequest(request, response) { | ||
| 141 | 137 | .map(tool => tool.function) |
| 142 | 138 | .map(fn => ({ name: fn.name, description: fn.description, input_schema: fn.parameters })); |
| 143 | 139 | |
| 140 | + // Claude doesn't do prefills on function calls, and doesn't allow empty messages | |
| 141 | + if (requestBody.tools.length && convertedPrompt.messages.length && convertedPrompt.messages[convertedPrompt.messages.length - 1].role === 'assistant') { | |
| 142 | + convertedPrompt.messages.push({ role: 'user', content: [{ type: 'text', text: '\u200b' }] }); | |
| 143 | + } | |
| 144 | 144 | if (enableSystemPromptCache && requestBody.tools.length) { |
| 145 | 145 | requestBody.tools[requestBody.tools.length - 1]['cache_control'] = { type: 'ephemeral' }; |
| 146 | 146 | } |