Merge pull request #1397 from aisu-wata0/claude_system_order_fix

This commit is contained in:
Cohee 2023-11-24 23:38:02 +02:00 committed by GitHub
commit 2c822f79f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

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