Fix Claude error in empty chats with no history

This commit is contained in:
Cohee 2024-03-12 01:17:35 +02:00
parent 5d561b64e2
commit c9c6d798d9
1 changed files with 2 additions and 1 deletions

View File

@ -101,7 +101,8 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
messages.splice(0, i); messages.splice(0, i);
// Check if the first message in the array is of type user, if not, interject with humanMsgFix or a blank message. // Check if the first message in the array is of type user, if not, interject with humanMsgFix or a blank message.
if (messages.length > 0 && messages[0].role !== 'user') { // Also prevents erroring out if the messages array is empty.
if (messages.length === 0 || (messages.length > 0 && messages[0].role !== 'user')) {
messages.unshift({ messages.unshift({
role: 'user', role: 'user',
content: humanMsgFix || '[Start a new chat]', content: humanMsgFix || '[Start a new chat]',