Fix tool call reuse between Claude and OAI

This commit is contained in:
Cohee
2024-10-06 22:22:19 +03:00
parent f7ec2e47d6
commit 6b022e783d
2 changed files with 12 additions and 2 deletions

View File

@ -131,13 +131,14 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
}
// Now replace all further messages that have the role 'system' with the role 'user'. (or all if we're not using one)
const parse = (str) => typeof str === 'string' ? JSON.parse(str) : str;
messages.forEach((message) => {
if (message.role === 'assistant' && message.tool_calls) {
message.content = message.tool_calls.map((tc) => ({
type: 'tool_use',
id: tc.id,
name: tc.function.name,
input: tc.function.arguments,
input: parse(tc.function.arguments),
}));
}