From ac33e4d66804470dc3e112eb21472a24a52f44c1 Mon Sep 17 00:00:00 2001 From: Honey Tree Date: Sun, 17 Nov 2024 09:21:20 -0300 Subject: [PATCH] cache_control positioning fix --- src/endpoints/backends/chat-completions.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/endpoints/backends/chat-completions.js b/src/endpoints/backends/chat-completions.js index e30902086..580e4388f 100644 --- a/src/endpoints/backends/chat-completions.js +++ b/src/endpoints/backends/chat-completions.js @@ -146,11 +146,13 @@ async function sendClaudeRequest(request, response) { cachingAtDepth += convertedPrompt.messages[messageCount - 1].role === 'assistant' ? 1 : 0; if (messageCount - 1 - cachingAtDepth >= 0) { - convertedPrompt.messages[messageCount - 1 - cachingAtDepth]['cache_control'] = { type: 'ephemeral' }; + const contentCount = convertedPrompt.messages[messageCount - 1 - cachingAtDepth].content.length; + convertedPrompt.messages[messageCount - 1 - cachingAtDepth].content[contentCount - 1]['cache_control'] = { type: 'ephemeral' }; } if (messageCount - 1 - cachingAtDepth - 2 >= 0) { - convertedPrompt.messages[messageCount - 1 - cachingAtDepth - 2]['cache_control'] = { type: 'ephemeral' }; + const contentCount = convertedPrompt.messages[messageCount - 1 - cachingAtDepth].content.length; + convertedPrompt.messages[messageCount - 1 - cachingAtDepth - 2].content[contentCount - 1]['cache_control'] = { type: 'ephemeral' }; } }