diff --git a/public/script.js b/public/script.js index c92d2d7aa..14ecee400 100644 --- a/public/script.js +++ b/public/script.js @@ -3796,7 +3796,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro coreChat.splice(coreChat.length - 1, 0, { mes: jailbreak, is_user: true }); } else { + // This operation will result in the injectedIndices indexes being off by one coreChat.push({ mes: jailbreak, is_user: true }); + // Add +1 to the elements to correct for the new PHI/Jailbreak message. + injectedIndices.forEach((e, idx) => injectedIndices[idx] = e + 1); } } } @@ -4757,7 +4760,7 @@ async function doChatInject(messages, isContinue) { if (roleMessages.length) { const depth = isContinue && i === 0 ? 1 : i; - const injectIdx = depth + totalInsertedMessages; + const injectIdx = Math.min(depth + totalInsertedMessages, messages.length); messages.splice(injectIdx, 0, ...roleMessages); totalInsertedMessages += roleMessages.length; injectedIndices.push(...Array.from({ length: roleMessages.length }, (_, i) => injectIdx + i));