Claude: fix token counting when tool_calls are used

This commit is contained in:
Cohee 2024-10-04 12:24:10 +00:00
parent 8c095f204a
commit cc3cc58a06
1 changed files with 8 additions and 0 deletions

View File

@ -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 {