Fix continuation suffix trimming Fixes #3901

b3e51c8b1c82e0cb1279a8f83e2b4d0ab44b60cc

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +9 -1Ignore whitespace
public/script.js+9 -1
@@ -4235,12 +4235,20 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
42354235
42364236 // Do not suffix the message for continuation
42374237 if (i === 0 && isContinue) {
4238+ // Pick something that's very unlikely to be in a message
4239+ const FORMAT_TOKEN = '\u0000\ufffc\u0000\ufffd';
4240+
42384241 if (isInstruct) {
4242+ const originalMessage = String(coreChat[j].mes ?? '');
4243+ coreChat[j].mes = originalMessage.replaceAll(FORMAT_TOKEN, '') + FORMAT_TOKEN;
42394244 // Reformat with the last output sequence (if any)
42404245 chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.LAST);
4246+ coreChat[j].mes = originalMessage;
42414247 }
42424248
4243- chat2[i] = chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length);
4249+ chat2[i] = chat2[i].includes(FORMAT_TOKEN)
4250+ ? chat2[i].slice(0, chat2[i].lastIndexOf(FORMAT_TOKEN))
4251+ : chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length);
42444252 continue_mag = coreChat[j].mes;
42454253 }
42464254