From b3e51c8b1c82e0cb1279a8f83e2b4d0ab44b60cc Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 25 Apr 2025 20:20:53 +0300 Subject: [PATCH] Fix continuation suffix trimming Fixes #3901 --- public/script.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index ca5f87850..87418da02 100644 --- a/public/script.js +++ b/public/script.js @@ -4235,12 +4235,20 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro // Do not suffix the message for continuation if (i === 0 && isContinue) { + // Pick something that's very unlikely to be in a message + const FORMAT_TOKEN = '\u0000\ufffc\u0000\ufffd'; + if (isInstruct) { + const originalMessage = String(coreChat[j].mes ?? ''); + coreChat[j].mes = originalMessage.replaceAll(FORMAT_TOKEN, '') + FORMAT_TOKEN; // Reformat with the last output sequence (if any) chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.LAST); + coreChat[j].mes = originalMessage; } - chat2[i] = chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length); + chat2[i] = chat2[i].includes(FORMAT_TOKEN) + ? chat2[i].slice(0, chat2[i].lastIndexOf(FORMAT_TOKEN)) + : chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length); continue_mag = coreChat[j].mes; }