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
mergedMessages.forEach((message) => {
if (message.name) {
const content = Array.isArray(message.content) ? message.content : [message.content];
for (let i = 0; i < content.length; i++) {
if (typeof content[i] === 'string') {
content[i] = `${message.name}: ${content[i]}`;
} else if (typeof content[i].text === 'string') {
content[i].text = `${message.name}: ${content[i].text}`;
}
if (Array.isArray(message.content)) {
message.content[0].text = `${message.name}: ${message.content[0].text}`;
} else {
message.content = `${message.name}: ${message.content}`;
}
delete message.name;
}