Allow running generate interceptors on quiet prompts

2f5f9a437dffd43f9767a6298eb2d60485580273

Cohee <18619528+Cohee1207@users.noreply.github.com>

4 files changed, +22 -7Showing whitespace changes
public/script.js+2 -2
@@ -3764,9 +3764,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
3764 // Determine token limit3764 // Determine token limit
3765 let this_max_context = getMaxContextSize();3765 let this_max_context = getMaxContextSize();
37663766
3767 if (!dryRun && type !== 'quiet') {3767 if (!dryRun) {
3768 console.debug('Running extension interceptors');3768 console.debug('Running extension interceptors');
3769 const aborted = await runGenerationInterceptors(coreChat, this_max_context);3769 const aborted = await runGenerationInterceptors(coreChat, this_max_context, type);
37703770
3771 if (aborted) {3771 if (aborted) {
3772 console.debug('Generation aborted by extension interceptors');3772 console.debug('Generation aborted by extension interceptors');
public/scripts/extensions.js+3 -2
@@ -1209,9 +1209,10 @@ async function autoUpdateExtensions(forceAll) {
1209 * Runs the generate interceptors for all extensions.1209 * Runs the generate interceptors for all extensions.
1210 * @param {any[]} chat Chat array1210 * @param {any[]} chat Chat array
1211 * @param {number} contextSize Context size1211 * @param {number} contextSize Context size
1212 * @param {string} type Generation type
1212 * @returns {Promise<boolean>} True if generation should be aborted1213 * @returns {Promise<boolean>} True if generation should be aborted
1213 */1214 */
1214export async function runGenerationInterceptors(chat, contextSize) {1215export async function runGenerationInterceptors(chat, contextSize, type) {
1215 let aborted = false;1216 let aborted = false;
1216 let exitImmediately = false;1217 let exitImmediately = false;
12171218
@@ -1224,7 +1225,7 @@ export async function runGenerationInterceptors(chat, contextSize) {
1224 const interceptorKey = manifest.generate_interceptor;1225 const interceptorKey = manifest.generate_interceptor;
1225 if (typeof globalThis[interceptorKey] === 'function') {1226 if (typeof globalThis[interceptorKey] === 'function') {
1226 try {1227 try {
1227 await globalThis[interceptorKey](chat, contextSize, abort);1228 await globalThis[interceptorKey](chat, contextSize, abort, type);
1228 } catch (e) {1229 } catch (e) {
1229 console.error(`Failed running interceptor for ${manifest.display_name}`, e);1230 console.error(`Failed running interceptor for ${manifest.display_name}`, e);
1230 }1231 }
public/scripts/extensions/stable-diffusion/index.js+12 -1
@@ -330,7 +330,18 @@ const defaultSettings = {
330330
331const writePromptFieldsDebounced = debounce(writePromptFields, debounce_timeout.relaxed);331const writePromptFieldsDebounced = debounce(writePromptFields, debounce_timeout.relaxed);
332332
333function processTriggers(chat, _, abort) {333/**
334 * Generate interceptor for interactive mode triggers.
335 * @param {any[]} chat Chat messages
336 * @param {number} _ Context size (unused)
337 * @param {function(boolean): void} abort Abort generation function
338 * @param {string} type Type of the generation
339 */
340function processTriggers(chat, _, abort, type) {
341 if (type === 'quiet') {
342 return;
343 }
344
334 if (extension_settings.sd.function_tool && ToolManager.isToolCallingSupported()) {345 if (extension_settings.sd.function_tool && ToolManager.isToolCallingSupported()) {
335 return;346 return;
336 }347 }
public/scripts/extensions/vectors/index.js+5 -2
@@ -594,8 +594,11 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overla
594/**594/**
595 * Removes the most relevant messages from the chat and displays them in the extension prompt595 * Removes the most relevant messages from the chat and displays them in the extension prompt
596 * @param {object[]} chat Array of chat messages596 * @param {object[]} chat Array of chat messages
597 * @param {number} _contextSize Context size (unused)
598 * @param {function} _abort Abort function (unused)
599 * @param {string} type Generation type
597 */600 */
598async function rearrangeChat(chat) {601async function rearrangeChat(chat, _contextSize, _abort, type) {
599 try {602 try {
600 // Clear the extension prompt603 // Clear the extension prompt
601 setExtensionPrompt(EXTENSION_PROMPT_TAG, '', settings.position, settings.depth, settings.include_wi);604 setExtensionPrompt(EXTENSION_PROMPT_TAG, '', settings.position, settings.depth, settings.include_wi);
@@ -609,7 +612,7 @@ async function rearrangeChat(chat) {
609 await activateWorldInfo(chat);612 await activateWorldInfo(chat);
610 }613 }
611614
612 if (!settings.enabled_chats) {615 if (!settings.enabled_chats || type === 'quiet') {
613 return;616 return;
614 }617 }
615618