Set prefill before squashing messages

This commit is contained in:
Cohee 2024-03-14 14:51:56 +02:00
parent 6ac8ef1b48
commit 94230c0891
1 changed files with 8 additions and 8 deletions

View File

@ -122,6 +122,14 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
}
});
// Shouldn't be conditional anymore, messages api expects the last role to be user unless we're explicitly prefilling
if (prefillString) {
messages.push({
role: 'assistant',
content: prefillString.trimEnd(),
});
}
// Since the messaging endpoint only supports user assistant roles in turns, we have to merge messages with the same role if they follow eachother
// Also handle multi-modality, holy slop.
let mergedMessages = [];
@ -172,14 +180,6 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
}
});
// Shouldn't be conditional anymore, messages api expects the last role to be user unless we're explicitly prefilling
if (prefillString) {
mergedMessages.push({
role: 'assistant',
content: prefillString.trimEnd(),
});
}
return { messages: mergedMessages, systemPrompt: systemPrompt.trim() };
}