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