cache_control positioning fix

ac33e4d66804470dc3e112eb21472a24a52f44c1

Honey Tree <kalakanlogs@proton.me>

1 files changed, +4 -2Showing whitespace changes
src/endpoints/backends/chat-completions.js+4 -2
@@ -146,11 +146,13 @@ async function sendClaudeRequest(request, response) {
146 cachingAtDepth += convertedPrompt.messages[messageCount - 1].role === 'assistant' ? 1 : 0;146 cachingAtDepth += convertedPrompt.messages[messageCount - 1].role === 'assistant' ? 1 : 0;
147147
148 if (messageCount - 1 - cachingAtDepth >= 0) {148 if (messageCount - 1 - cachingAtDepth >= 0) {
149 convertedPrompt.messages[messageCount - 1 - cachingAtDepth]['cache_control'] = { type: 'ephemeral' };149 const contentCount = convertedPrompt.messages[messageCount - 1 - cachingAtDepth].content.length;
150 convertedPrompt.messages[messageCount - 1 - cachingAtDepth].content[contentCount - 1]['cache_control'] = { type: 'ephemeral' };
150 }151 }
151152
152 if (messageCount - 1 - cachingAtDepth - 2 >= 0) {153 if (messageCount - 1 - cachingAtDepth - 2 >= 0) {
153 convertedPrompt.messages[messageCount - 1 - cachingAtDepth - 2]['cache_control'] = { type: 'ephemeral' };154 const contentCount = convertedPrompt.messages[messageCount - 1 - cachingAtDepth].content.length;
155 convertedPrompt.messages[messageCount - 1 - cachingAtDepth - 2].content[contentCount - 1]['cache_control'] = { type: 'ephemeral' };
154 }156 }
155 }157 }
156158