Regex script: promptOnly modifies coreChat

This commit is contained in:
Aisu Wata
2023-11-04 15:14:59 -03:00
parent 4ec40d575e
commit 4bdfd9d164

View File

@@ -2441,14 +2441,6 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
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) { if (selected_group && !is_group_generating && !dryRun) {
generateGroupWrapper(false, type, { resolve, reject, quiet_prompt, force_chid, signal: abortController.signal }); generateGroupWrapper(false, type, { resolve, reject, quiet_prompt, force_chid, signal: abortController.signal });
return; return;
@@ -2493,34 +2485,34 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
$("#send_textarea").val('').trigger('input'); $("#send_textarea").val('').trigger('input');
} else { } else {
textareaText = ""; 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? //do nothing? why does this check exist?
} }
else if (type !== 'quiet' && type !== "swipe" && !isImpersonate && !dryRun && chat_regexed.length) { else if (type !== 'quiet' && type !== "swipe" && !isImpersonate && !dryRun && chat.length) {
chat_regexed.length = chat_regexed.length - 1; chat.length = chat.length - 1;
count_view_mes -= 1; count_view_mes -= 1;
$('#chat').children().last().hide(250, function () { $('#chat').children().last().hide(250, function () {
$(this).remove(); $(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'; type = 'continue';
} }
const isContinue = type == 'continue'; const isContinue = type == 'continue';
// Rewrite the generation timer to account for the time passed for all the continuations. // Rewrite the generation timer to account for the time passed for all the continuations.
if (isContinue && chat_regexed.length) { if (isContinue && chat.length) {
const prevFinished = chat_regexed[chat_regexed.length - 1]['gen_finished']; const prevFinished = chat[chat.length - 1]['gen_finished'];
const prevStarted = chat_regexed[chat_regexed.length - 1]['gen_started']; const prevStarted = chat[chat.length - 1]['gen_started'];
if (prevFinished && prevStarted) { if (prevFinished && prevStarted) {
const timePassed = prevFinished - prevStarted; const timePassed = prevFinished - prevStarted;
generation_started = new Date(Date.now() - timePassed); 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 = [] mesExamplesArray = []
// First message in fresh 1-on-1 chat reacts to user/character settings changes // First message in fresh 1-on-1 chat reacts to user/character settings changes
if (chat_regexed.length) { if (chat.length) {
chat_regexed[0].mes = substituteParams(chat_regexed[0].mes); chat[0].mes = substituteParams(chat[0].mes);
} }
// Collect messages with usable content // 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') { if (type === 'swipe') {
coreChat.pop(); 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 // Determine token limit
let this_max_context = getMaxContextSize(); 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.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 // 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') { if ((promptBias && !isUserPromptBias) || power_user.always_force_name2 || main_api == 'novel') {