diff --git a/public/script.js b/public/script.js index c35cf5221..141b0b3de 100644 --- a/public/script.js +++ b/public/script.js @@ -2702,7 +2702,7 @@ class StreamingProcessor { * Generates a message using the provided prompt. * @param {string} prompt Prompt to generate a message from * @param {string} api API to use. Main API is used if not specified. - * @param {string} instructOverride If 0, false or off, disables instruct formatting + * @param {boolean} instructOverride true to override instruct mode, false to use the default value * @returns {Promise} Generated message */ export async function generateRaw(prompt, api, instructOverride) { @@ -2711,8 +2711,7 @@ export async function generateRaw(prompt, api, instructOverride) { } const abortController = new AbortController(); - const instructDisabled = instructOverride === '0' || instructOverride === 'false' || instructOverride === 'off'; - const isInstruct = power_user.instruct.enabled && main_api !== 'openai' && main_api !== 'novel' && !instructDisabled; + const isInstruct = power_user.instruct.enabled && main_api !== 'openai' && main_api !== 'novel' && !instructOverride; prompt = substituteParams(prompt); prompt = api == 'novel' ? adjustNovelInstructionPrompt(prompt) : prompt; diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 9d7f4b1ca..4a29e73b1 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -26,6 +26,8 @@ import { setCharacterName, generateRaw, callPopup, + deactivateSendButtons, + activateSendButtons, } from "../script.js"; import { getMessageTimeStamp } from "./RossAscends-mods.js"; import { findGroupMemberId, groups, is_group_generating, resetSelectedGroup, saveGroupChat, selected_group } from "./group-chats.js"; @@ -34,7 +36,7 @@ import { addEphemeralStoppingString, chat_styles, power_user } from "./power-use import { autoSelectPersona } from "./personas.js"; import { getContext } from "./extensions.js"; import { hideChatMessage, unhideChatMessage } from "./chats.js"; -import { delay, stringToRange } from "./utils.js"; +import { delay, isFalseBoolean, isTrueBoolean, stringToRange } from "./utils.js"; import { registerVariableCommands } from "./variables.js"; export { executeSlashCommands, @@ -161,8 +163,8 @@ parser.addCommand('memberdown', moveGroupMemberDownCallback, ['downmember'], '(message index or range) – shows a group member character card without switching chats', true, true); parser.addCommand('delswipe', deleteSwipeCallback, ['swipedel'], '(optional 1-based id) – deletes a swipe from the last chat message. If swipe id not provided - deletes the current swipe.', true, true); parser.addCommand('echo', echoCallback, [], '(text) – echoes the text to toast message. Useful for pipes debugging.', true, true); -parser.addCommand('gen', generateCallback, [], '(prompt) – generates text using the provided prompt and passes it to the next command through the pipe.', true, true); -parser.addCommand('genraw', generateRawCallback, [], '(prompt) – 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. /genraw instruct=off Why is the sky blue?. Use stop=... with a JSON-serialized array to add one-time custom stop strings, e.g. /genraw stop=["\\n"] Say hi', true, true); +parser.addCommand('gen', generateCallback, [], '(lock=on/off [prompt]) – generates text using the provided prompt and passes it to the next command through the pipe, optionally locking user input while generating.', true, true); +parser.addCommand('genraw', generateRawCallback, [], '(lock=on/off [prompt]) – generates text using the provided prompt and passes it to the next command through the pipe, optionally locking user input while generating. Does not include chat history or character card. Use instruct=off to skip instruct formatting, e.g. /genraw instruct=off Why is the sky blue?. Use stop=... with a JSON-serialized array to add one-time custom stop strings, e.g. /genraw stop=["\\n"] Say hi', true, true); parser.addCommand('addswipe', addSwipeCallback, ['swipeadd'], '(text) – adds a swipe to the last chat message.', true, true); parser.addCommand('abort', abortCallback, [], ' – aborts the slash command batch execution', true, true); parser.addCommand('fuzzy', fuzzyCallback, [], 'list=["a","b","c"] (search value) – performs a fuzzy match of the provided search using the provided list of value and passes the closest match to the next command through the pipe.', true, true); @@ -242,6 +244,7 @@ async function generateRawCallback(args, value) { // Prevent generate recursion $('#send_textarea').val(''); + const lock = isTrueBoolean(args?.lock); if (typeof args.stop === 'string' && args.stop.length) { try { @@ -256,21 +259,42 @@ async function generateRawCallback(args, value) { } } - const result = await generateRaw(value, '', args.instruct); - return result; + try { + if (lock) { + deactivateSendButtons(); + } + + const result = await generateRaw(value, '', isFalseBoolean(args?.instruct)); + return result; + } finally { + if (lock) { + activateSendButtons(); + } + } } -async function generateCallback(_, arg) { - if (!arg) { +async function generateCallback(args, value) { + if (!value) { console.warn('WARN: No argument provided for /gen command'); return; } // Prevent generate recursion $('#send_textarea').val(''); + const lock = isTrueBoolean(args?.lock); - const result = await generateQuietPrompt(arg, false, false, ''); - return result; + try { + if (lock) { + deactivateSendButtons(); + } + + const result = await generateQuietPrompt(value, false, false, ''); + return result; + } finally { + if (lock) { + activateSendButtons(); + } + } } async function echoCallback(_, arg) { diff --git a/public/scripts/utils.js b/public/scripts/utils.js index 571583240..a025bb94d 100644 --- a/public/scripts/utils.js +++ b/public/scripts/utils.js @@ -565,6 +565,24 @@ export function countOccurrences(string, character) { return count; } +/** + * Checks if a string is "true" value. + * @param {string} arg String to check + * @returns {boolean} True if the string is true, false otherwise. + */ +export function isTrueBoolean(arg) { + return ['on', 'true', '1'].includes(arg); +} + +/** + * Checks if a string is "false" value. + * @param {string} arg String to check + * @returns {boolean} True if the string is false, false otherwise. + */ +export function isFalseBoolean(arg) { + return ['off', 'false', '0'].includes(arg); +} + /** * Checks if a number is odd. * @param {number} number The number to check.