Merge pull request #3913 from SillyTavern/fix-continue-suffix Fix continuation suffix trimming

84f339cdd652a18af83f9506a07de7b961a1ca77

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

Signed
1 files changed, +9 -1Ignore whitespace
public/script.js+9 -1
@@ -4237,12 +4237,20 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
42374237
42384238 // Do not suffix the message for continuation
42394239 if (i === 0 && isContinue) {
4240+ // Pick something that's very unlikely to be in a message
4241+ const FORMAT_TOKEN = '\u0000\ufffc\u0000\ufffd';
4242+
42404243 if (isInstruct) {
4244+ const originalMessage = String(coreChat[j].mes ?? '');
4245+ coreChat[j].mes = originalMessage.replaceAll(FORMAT_TOKEN, '') + FORMAT_TOKEN;
42414246 // Reformat with the last output sequence (if any)
42424247 chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.LAST);
4248+ coreChat[j].mes = originalMessage;
42434249 }
42444250
4245- chat2[i] = chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length);
4251+ chat2[i] = chat2[i].includes(FORMAT_TOKEN)
4252+ ? chat2[i].slice(0, chat2[i].lastIndexOf(FORMAT_TOKEN))
4253+ : chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length);
42464254 continue_mag = coreChat[j].mes;
42474255 }
42484256