Fix ephemeral stopping strings flush

This commit is contained in:
Cohee
2023-11-24 19:06:31 +02:00
parent 2c8e855385
commit a178bdc3b0
2 changed files with 24 additions and 14 deletions

View File

@ -2388,6 +2388,10 @@ export function addEphemeralStoppingString(value) {
} }
export function flushEphemeralStoppingStrings() { export function flushEphemeralStoppingStrings() {
if (EPHEMERAL_STOPPING_STRINGS.length === 0) {
return;
}
console.debug('Flushing ephemeral stopping strings:', EPHEMERAL_STOPPING_STRINGS); console.debug('Flushing ephemeral stopping strings:', EPHEMERAL_STOPPING_STRINGS);
EPHEMERAL_STOPPING_STRINGS.length = 0; EPHEMERAL_STOPPING_STRINGS.length = 0;
} }

View File

@ -32,7 +32,7 @@ import {
import { getMessageTimeStamp } from "./RossAscends-mods.js"; import { getMessageTimeStamp } from "./RossAscends-mods.js";
import { findGroupMemberId, groups, is_group_generating, resetSelectedGroup, saveGroupChat, selected_group } from "./group-chats.js"; import { findGroupMemberId, groups, is_group_generating, resetSelectedGroup, saveGroupChat, selected_group } from "./group-chats.js";
import { getRegexedString, regex_placement } from "./extensions/regex/engine.js"; import { getRegexedString, regex_placement } from "./extensions/regex/engine.js";
import { addEphemeralStoppingString, chat_styles, power_user } from "./power-user.js"; import { addEphemeralStoppingString, chat_styles, flushEphemeralStoppingStrings, power_user } from "./power-user.js";
import { autoSelectPersona } from "./personas.js"; import { autoSelectPersona } from "./personas.js";
import { getContext } from "./extensions.js"; import { getContext } from "./extensions.js";
import { hideChatMessage, unhideChatMessage } from "./chats.js"; import { hideChatMessage, unhideChatMessage } from "./chats.js";
@ -292,6 +292,21 @@ function fuzzyCallback(args, value) {
} }
} }
function setEphemeralStopStrings(value) {
if (typeof value === 'string' && value.length) {
try {
const stopStrings = JSON.parse(value);
if (Array.isArray(stopStrings)) {
for (const stopString of stopStrings) {
addEphemeralStoppingString(stopString);
}
}
} catch {
// Do nothing
}
}
}
async function generateRawCallback(args, value) { async function generateRawCallback(args, value) {
if (!value) { if (!value) {
console.warn('WARN: No argument provided for /genraw command'); console.warn('WARN: No argument provided for /genraw command');
@ -302,30 +317,19 @@ async function generateRawCallback(args, value) {
$('#send_textarea').val('').trigger('input'); $('#send_textarea').val('').trigger('input');
const lock = isTrueBoolean(args?.lock); const lock = isTrueBoolean(args?.lock);
if (typeof args.stop === 'string' && args.stop.length) {
try {
const stopStrings = JSON.parse(args.stop);
if (Array.isArray(stopStrings)) {
for (const stopString of stopStrings) {
addEphemeralStoppingString(stopString);
}
}
} catch {
// Do nothing
}
}
try { try {
if (lock) { if (lock) {
deactivateSendButtons(); deactivateSendButtons();
} }
setEphemeralStopStrings(args?.stop);
const result = await generateRaw(value, '', isFalseBoolean(args?.instruct)); const result = await generateRaw(value, '', isFalseBoolean(args?.instruct));
return result; return result;
} finally { } finally {
if (lock) { if (lock) {
activateSendButtons(); activateSendButtons();
} }
flushEphemeralStoppingStrings();
} }
} }
@ -344,12 +348,14 @@ async function generateCallback(args, value) {
deactivateSendButtons(); deactivateSendButtons();
} }
setEphemeralStopStrings(args?.stop);
const result = await generateQuietPrompt(value, false, false, ''); const result = await generateQuietPrompt(value, false, false, '');
return result; return result;
} finally { } finally {
if (lock) { if (lock) {
activateSendButtons(); activateSendButtons();
} }
flushEphemeralStoppingStrings();
} }
} }