| 4237 | | 4237 | |
| 4238 | // Do not suffix the message for continuation | 4238 | // 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 | } |
| 4244 | | 4250 | |
| 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 | } |
| 4248 | | 4256 | |