From cc3cc58a06a7ecfd841e4ddad8f7190c61da5d98 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:24:10 +0000 Subject: [PATCH] Claude: fix token counting when tool_calls are used --- src/prompt-converters.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/prompt-converters.js b/src/prompt-converters.js index b4b3d718b..ceb3c1189 100644 --- a/src/prompt-converters.js +++ b/src/prompt-converters.js @@ -19,6 +19,14 @@ function convertClaudePrompt(messages, addAssistantPostfix, addAssistantPrefill, //Prepare messages for claude. //When 'Exclude Human/Assistant prefixes' checked, setting messages role to the 'system'(last message is exception). if (messages.length > 0) { + messages.forEach((m) => { + if (!m.content) { + m.content = ''; + } + if (m.tool_calls) { + m.content += JSON.stringify(m.tool_calls); + } + }); if (excludePrefixes) { messages.slice(0, -1).forEach(message => message.role = 'system'); } else {