Add ephemeral stop strings to /genraw
This commit is contained in:
parent
c2e3bfa06d
commit
863554fea6
|
@ -82,6 +82,7 @@ import {
|
||||||
registerDebugFunction,
|
registerDebugFunction,
|
||||||
ui_mode,
|
ui_mode,
|
||||||
switchSimpleMode,
|
switchSimpleMode,
|
||||||
|
flushEphemeralStoppingStrings,
|
||||||
} from "./scripts/power-user.js";
|
} from "./scripts/power-user.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -3837,6 +3838,7 @@ function unblockGeneration() {
|
||||||
activateSendButtons();
|
activateSendButtons();
|
||||||
showSwipeButtons();
|
showSwipeButtons();
|
||||||
setGenerationProgress(0);
|
setGenerationProgress(0);
|
||||||
|
flushEphemeralStoppingStrings();
|
||||||
$("#send_textarea").removeAttr('disabled');
|
$("#send_textarea").removeAttr('disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2374,45 +2374,69 @@ async function setmovingUIPreset(_, text) {
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EPHEMERAL_STOPPING_STRINGS = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a stopping string to the list of stopping strings that are only used for the next generation.
|
||||||
|
* @param {string} value The stopping string to add
|
||||||
|
*/
|
||||||
|
export function addEphemeralStoppingString(value) {
|
||||||
|
if (!EPHEMERAL_STOPPING_STRINGS.includes(value)) {
|
||||||
|
console.debug('Adding ephemeral stopping string:', value);
|
||||||
|
EPHEMERAL_STOPPING_STRINGS.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function flushEphemeralStoppingStrings() {
|
||||||
|
console.debug('Flushing ephemeral stopping strings:', EPHEMERAL_STOPPING_STRINGS);
|
||||||
|
EPHEMERAL_STOPPING_STRINGS.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the custom stopping strings from the power user settings.
|
* Gets the custom stopping strings from the power user settings.
|
||||||
* @param {number | undefined} limit Number of strings to return. If 0 or undefined, returns all strings.
|
* @param {number | undefined} limit Number of strings to return. If 0 or undefined, returns all strings.
|
||||||
* @returns {string[]} An array of custom stopping strings
|
* @returns {string[]} An array of custom stopping strings
|
||||||
*/
|
*/
|
||||||
export function getCustomStoppingStrings(limit = undefined) {
|
export function getCustomStoppingStrings(limit = undefined) {
|
||||||
try {
|
function getPermanent() {
|
||||||
// If there's no custom stopping strings, return an empty array
|
try {
|
||||||
if (!power_user.custom_stopping_strings) {
|
// If there's no custom stopping strings, return an empty array
|
||||||
|
if (!power_user.custom_stopping_strings) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the JSON string
|
||||||
|
let strings = JSON.parse(power_user.custom_stopping_strings);
|
||||||
|
|
||||||
|
// Make sure it's an array
|
||||||
|
if (!Array.isArray(strings)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure all the elements are strings and non-empty.
|
||||||
|
strings = strings.filter(s => typeof s === 'string' && s.length > 0);
|
||||||
|
|
||||||
|
// Substitute params if necessary
|
||||||
|
if (power_user.custom_stopping_strings_macro) {
|
||||||
|
strings = strings.map(x => substituteParams(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the limit. If limit is 0, return all strings.
|
||||||
|
if (limit > 0) {
|
||||||
|
strings = strings.slice(0, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings;
|
||||||
|
} catch (error) {
|
||||||
|
// If there's an error, return an empty array
|
||||||
|
console.warn('Error parsing custom stopping strings:', error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the JSON string
|
|
||||||
let strings = JSON.parse(power_user.custom_stopping_strings);
|
|
||||||
|
|
||||||
// Make sure it's an array
|
|
||||||
if (!Array.isArray(strings)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure all the elements are strings and non-empty.
|
|
||||||
strings = strings.filter(s => typeof s === 'string' && s.length > 0);
|
|
||||||
|
|
||||||
// Substitute params if necessary
|
|
||||||
if (power_user.custom_stopping_strings_macro) {
|
|
||||||
strings = strings.map(x => substituteParams(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply the limit. If limit is 0, return all strings.
|
|
||||||
if (limit > 0) {
|
|
||||||
strings = strings.slice(0, limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings;
|
|
||||||
} catch (error) {
|
|
||||||
// If there's an error, return an empty array
|
|
||||||
console.warn('Error parsing custom stopping strings:', error);
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const permanent = getPermanent();
|
||||||
|
const ephemeral = EPHEMERAL_STOPPING_STRINGS;
|
||||||
|
return [...permanent, ...ephemeral];
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
|
|
|
@ -29,7 +29,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 { chat_styles, power_user } from "./power-user.js";
|
import { addEphemeralStoppingString, chat_styles, 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";
|
||||||
|
@ -161,7 +161,7 @@ parser.addCommand('peek', peekCallback, [], '<span class="monospace">(message in
|
||||||
parser.addCommand('delswipe', deleteSwipeCallback, ['swipedel'], '<span class="monospace">(optional 1-based id)</span> – deletes a swipe from the last chat message. If swipe id not provided - deletes the current swipe.', true, true);
|
parser.addCommand('delswipe', deleteSwipeCallback, ['swipedel'], '<span class="monospace">(optional 1-based id)</span> – deletes a swipe from the last chat message. If swipe id not provided - deletes the current swipe.', true, true);
|
||||||
parser.addCommand('echo', echoCallback, [], '<span class="monospace">(text)</span> – echoes the text to toast message. Useful for pipes debugging.', true, true);
|
parser.addCommand('echo', echoCallback, [], '<span class="monospace">(text)</span> – echoes the text to toast message. Useful for pipes debugging.', true, true);
|
||||||
parser.addCommand('gen', generateCallback, [], '<span class="monospace">(prompt)</span> – generates text using the provided prompt and passes it to the next command through the pipe.', true, true);
|
parser.addCommand('gen', generateCallback, [], '<span class="monospace">(prompt)</span> – generates text using the provided prompt and passes it to the next command through the pipe.', true, true);
|
||||||
parser.addCommand('genraw', generateRawCallback, [], '<span class="monospace">(prompt)</span> – generates text using the provided prompt and passes it to the next command through the pipe. Does not include chat history or character card. Use instruct=off to skip instruct formatting, e.g. <tt>/genraw instruct=off Why is the sky blue?</tt>', true, true);
|
parser.addCommand('genraw', generateRawCallback, [], '<span class="monospace">(prompt)</span> – generates text using the provided prompt and passes it to the next command through the pipe. Does not include chat history or character card. Use instruct=off to skip instruct formatting, e.g. <tt>/genraw instruct=off Why is the sky blue?</tt>. Use stop=... with a JSON-serializer array to add one-time custom stop strings, e.g. <tt>/genraw stop=["\\n"] Say hi</tt>', true, true);
|
||||||
parser.addCommand('addswipe', addSwipeCallback, ['swipeadd'], '<span class="monospace">(text)</span> – adds a swipe to the last chat message.', true, true);
|
parser.addCommand('addswipe', addSwipeCallback, ['swipeadd'], '<span class="monospace">(text)</span> – adds a swipe to the last chat message.', true, true);
|
||||||
parser.addCommand('abort', abortCallback, [], ' – aborts the slash command batch execution', true, true);
|
parser.addCommand('abort', abortCallback, [], ' – aborts the slash command batch execution', true, true);
|
||||||
registerVariableCommands();
|
registerVariableCommands();
|
||||||
|
@ -184,6 +184,19 @@ async function generateRawCallback(args, value) {
|
||||||
// Prevent generate recursion
|
// Prevent generate recursion
|
||||||
$('#send_textarea').val('');
|
$('#send_textarea').val('');
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const result = await generateRaw(value, '', args.instruct);
|
const result = await generateRaw(value, '', args.instruct);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue