Claude system message order fix

This commit is contained in:
Aisu Wata 2023-11-24 17:58:20 -03:00
parent 8e49ecce49
commit a6898365d1
1 changed files with 8 additions and 2 deletions

View File

@ -18,14 +18,20 @@ function convertClaudePrompt(messages, addHumanPrefix, addAssistantPostfix, with
let systemPrompt = '';
if (withSystemPrompt) {
for (const message of messages) {
let lastSystemIdx = -1;
for (let i = 0; i < messages.length - 1; i++) {
const message = messages[i];
if (message.role === "system" && !message.name) {
systemPrompt += message.content + '\n\n';
messages.splice(messages.indexOf(message), 1);
} else {
lastSystemIdx = i - 1;
break;
}
}
if (lastSystemIdx >= 0) {
messages.splice(0, lastSystemIdx + 1);
}
}
let requestPrompt = messages.map((v) => {