Fix continuation suffix trimming Fixes #3901

b3e51c8b1c82e0cb1279a8f83e2b4d0ab44b60cc

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

1 files changed, +9 -1Showing whitespace changes
public/script.js+9 -1
@@ -4235,12 +4235,20 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
42354235
4236 // Do not suffix the message for continuation4236 // Do not suffix the message for continuation
4237 if (i === 0 && isContinue) {4237 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
4238 if (isInstruct) {4241 if (isInstruct) {
4242 const originalMessage = String(coreChat[j].mes ?? '');
4243 coreChat[j].mes = originalMessage.replaceAll(FORMAT_TOKEN, '') + FORMAT_TOKEN;
4239 // Reformat with the last output sequence (if any)4244 // Reformat with the last output sequence (if any)
4240 chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.LAST);4245 chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.LAST);
4246 coreChat[j].mes = originalMessage;
4241 }4247 }
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);
4244 continue_mag = coreChat[j].mes;4252 continue_mag = coreChat[j].mes;
4245 }4253 }
42464254