Add user first and last prefixes for instruct

This commit is contained in:
Cohee
2024-07-26 23:10:09 +03:00
parent 475eca6fca
commit 39c63dc78b
5 changed files with 51 additions and 3 deletions

View File

@ -3611,6 +3611,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
let chat2 = [];
let continue_mag = '';
const userMessageIndices = [];
const lastUserMessageIndex = coreChat.findLastIndex(x => x.is_user);
for (let i = coreChat.length - 1, j = 0; i >= 0; i--, j++) {
if (main_api == 'openai') {
@ -3629,6 +3630,11 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.FIRST);
}
if (lastUserMessageIndex >= 0 && j === lastUserMessageIndex && isInstruct) {
// Reformat with the last input sequence (if any)
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.LAST);
}
// Do not suffix the message for continuation
if (i === 0 && isContinue) {
if (isInstruct) {
@ -3654,7 +3660,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
mes: power_user.instruct.user_alignment_message,
is_user: true,
};
userAlignmentMessage = formatMessageHistoryItem(alignmentMessage, isInstruct, false);
userAlignmentMessage = formatMessageHistoryItem(alignmentMessage, isInstruct, force_output_sequence.FIRST);
}
// Call combined AN into Generate