Fix case if message content is a string

This commit is contained in:
Cohee 2024-03-06 21:40:51 +02:00
parent 0ba6a562cb
commit 41e053c40d
1 changed files with 4 additions and 7 deletions

View File

@ -151,13 +151,10 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
// Take care of name properties since claude messages don't support them // Take care of name properties since claude messages don't support them
mergedMessages.forEach((message) => { mergedMessages.forEach((message) => {
if (message.name) { if (message.name) {
const content = Array.isArray(message.content) ? message.content : [message.content]; if (Array.isArray(message.content)) {
for (let i = 0; i < content.length; i++) { message.content[0].text = `${message.name}: ${message.content[0].text}`;
if (typeof content[i] === 'string') { } else {
content[i] = `${message.name}: ${content[i]}`; message.content = `${message.name}: ${message.content}`;
} else if (typeof content[i].text === 'string') {
content[i].text = `${message.name}: ${content[i].text}`;
}
} }
delete message.name; delete message.name;
} }