From 4bdfd9d1646d78d9f9509f94eb64635ec389366b Mon Sep 17 00:00:00 2001 From: Aisu Wata Date: Sat, 4 Nov 2023 15:14:59 -0300 Subject: [PATCH] Regex script: promptOnly modifies coreChat --- public/script.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/public/script.js b/public/script.js index 23500adab..0fa26bb73 100644 --- a/public/script.js +++ b/public/script.js @@ -2441,14 +2441,6 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, reject = () => { }; } - let chat_regexed = chat.map(x => ({ - ...x, - mes: getRegexedString(x.mes, x.is_user ? regex_placement.USER_INPUT : regex_placement.AI_OUTPUT, { - isPrompt: true, - }), - })) - - if (selected_group && !is_group_generating && !dryRun) { generateGroupWrapper(false, type, { resolve, reject, quiet_prompt, force_chid, signal: abortController.signal }); return; @@ -2493,34 +2485,34 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, $("#send_textarea").val('').trigger('input'); } else { textareaText = ""; - if (chat_regexed.length && chat_regexed[chat_regexed.length - 1]['is_user']) { + if (chat.length && chat[chat.length - 1]['is_user']) { //do nothing? why does this check exist? } - else if (type !== 'quiet' && type !== "swipe" && !isImpersonate && !dryRun && chat_regexed.length) { - chat_regexed.length = chat_regexed.length - 1; + else if (type !== 'quiet' && type !== "swipe" && !isImpersonate && !dryRun && chat.length) { + chat.length = chat.length - 1; count_view_mes -= 1; $('#chat').children().last().hide(250, function () { $(this).remove(); }); - await eventSource.emit(event_types.MESSAGE_DELETED, chat_regexed.length); + await eventSource.emit(event_types.MESSAGE_DELETED, chat.length); } } - if (!type && !textareaText && power_user.continue_on_send && !selected_group && chat_regexed.length && !chat_regexed[chat_regexed.length - 1]['is_user'] && !chat_regexed[chat_regexed.length - 1]['is_system']) { + if (!type && !textareaText && power_user.continue_on_send && !selected_group && chat.length && !chat[chat.length - 1]['is_user'] && !chat[chat.length - 1]['is_system']) { type = 'continue'; } const isContinue = type == 'continue'; // Rewrite the generation timer to account for the time passed for all the continuations. - if (isContinue && chat_regexed.length) { - const prevFinished = chat_regexed[chat_regexed.length - 1]['gen_finished']; - const prevStarted = chat_regexed[chat_regexed.length - 1]['gen_started']; + if (isContinue && chat.length) { + const prevFinished = chat[chat.length - 1]['gen_finished']; + const prevStarted = chat[chat.length - 1]['gen_started']; if (prevFinished && prevStarted) { const timePassed = prevFinished - prevStarted; generation_started = new Date(Date.now() - timePassed); - chat_regexed[chat_regexed.length - 1]['gen_started'] = generation_started; + chat[chat.length - 1]['gen_started'] = generation_started; } } @@ -2608,16 +2600,23 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, mesExamplesArray = [] // First message in fresh 1-on-1 chat reacts to user/character settings changes - if (chat_regexed.length) { - chat_regexed[0].mes = substituteParams(chat_regexed[0].mes); + if (chat.length) { + chat[0].mes = substituteParams(chat[0].mes); } // Collect messages with usable content - let coreChat = chat_regexed.filter(x => !x.is_system); + let coreChat = chat.filter(x => !x.is_system); if (type === 'swipe') { coreChat.pop(); } + coreChat = coreChat.map(x => ({ + ...x, + mes: getRegexedString(x.mes, x.is_user ? regex_placement.USER_INPUT : regex_placement.AI_OUTPUT, { + isPrompt: true, + }), + })) + // Determine token limit let this_max_context = getMaxContextSize(); @@ -2634,7 +2633,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, console.debug('Skipping extension interceptors for dry run'); } - console.log(`Core/all messages: ${coreChat.length}/${chat_regexed.length}`); + console.log(`Core/all messages: ${coreChat.length}/${chat.length}`); // kingbri MARK: - Make sure the prompt bias isn't the same as the user bias if ((promptBias && !isUserPromptBias) || power_user.always_force_name2 || main_api == 'novel') {