mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Claude: fix prefill tool calling hack with at-depth caching
This commit is contained in:
@ -474,6 +474,8 @@ label[for="trim_spaces"]:has(input:checked) i.warning {
|
|||||||
|
|
||||||
#claude_function_prefill_warning {
|
#claude_function_prefill_warning {
|
||||||
display: none;
|
display: none;
|
||||||
|
color: red;
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
#openai_settings:has(#openai_function_calling:checked):has(#claude_assistant_prefill:not(:placeholder-shown), #claude_assistant_impersonation:not(:placeholder-shown)) #claude_function_prefill_warning {
|
#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) {
|
|||||||
delete requestBody.system;
|
delete requestBody.system;
|
||||||
}
|
}
|
||||||
if (useTools) {
|
if (useTools) {
|
||||||
// Claude doesn't do prefills on function calls, and doesn't allow empty messages
|
|
||||||
if (convertedPrompt.messages.length && convertedPrompt.messages[convertedPrompt.messages.length - 1].role === 'assistant') {
|
|
||||||
convertedPrompt.messages.push({ role: 'user', content: '.' });
|
|
||||||
}
|
|
||||||
additionalHeaders['anthropic-beta'] = 'tools-2024-05-16';
|
additionalHeaders['anthropic-beta'] = 'tools-2024-05-16';
|
||||||
requestBody.tool_choice = { type: request.body.tool_choice };
|
requestBody.tool_choice = { type: request.body.tool_choice };
|
||||||
requestBody.tools = request.body.tools
|
requestBody.tools = request.body.tools
|
||||||
@ -141,6 +137,10 @@ async function sendClaudeRequest(request, response) {
|
|||||||
.map(tool => tool.function)
|
.map(tool => tool.function)
|
||||||
.map(fn => ({ name: fn.name, description: fn.description, input_schema: fn.parameters }));
|
.map(fn => ({ name: fn.name, description: fn.description, input_schema: fn.parameters }));
|
||||||
|
|
||||||
|
// Claude doesn't do prefills on function calls, and doesn't allow empty messages
|
||||||
|
if (requestBody.tools.length && convertedPrompt.messages.length && convertedPrompt.messages[convertedPrompt.messages.length - 1].role === 'assistant') {
|
||||||
|
convertedPrompt.messages.push({ role: 'user', content: [{ type: 'text', text: '\u200b' }] });
|
||||||
|
}
|
||||||
if (enableSystemPromptCache && requestBody.tools.length) {
|
if (enableSystemPromptCache && requestBody.tools.length) {
|
||||||
requestBody.tools[requestBody.tools.length - 1]['cache_control'] = { type: 'ephemeral' };
|
requestBody.tools[requestBody.tools.length - 1]['cache_control'] = { type: 'ephemeral' };
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user