Add quiet flags to /api and /summarize Closes #2661
| @@ -242,7 +242,7 @@ import { DragAndDropHandler } from './scripts/dragdrop.js'; | ||
| 242 | 242 | import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js'; |
| 243 | 243 | import { initDynamicStyles } from './scripts/dynamic-styles.js'; |
| 244 | 244 | import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js'; |
| 245 | 245 | import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 246 | 246 | |
| 247 | 247 | //exporting functions and vars for mods |
| 248 | 248 | export { |
| @@ -8465,7 +8465,7 @@ async function disableInstructCallback() { | ||
| 8465 | 8465 | /** |
| 8466 | 8466 | * @param {string} text API name |
| 8467 | 8467 | */ |
| 8468 | 8468 | async function connectAPISlash(_args, text) { |
| 8469 | 8469 | if (!text.trim()) { |
| 8470 | 8470 | for (const [key, config] of Object.entries(CONNECT_API_MAP)) { |
| 8471 | 8471 | if (config.selected !== main_api) continue; |
| @@ -8493,7 +8493,7 @@ async function connectAPISlash(_, text) { | ||
| 8493 | 8493 | const apiConfig = CONNECT_API_MAP[text.toLowerCase()]; |
| 8494 | 8494 | if (!apiConfig) { |
| 8495 | 8495 | toastr.error(`Error: ${text} is not a valid API`); |
| 8496 | 8496 | return ''; |
| 8497 | 8497 | } |
| 8498 | 8498 | |
| 8499 | 8499 | $(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true); |
| @@ -8513,14 +8513,17 @@ async function connectAPISlash(_, text) { | ||
| 8513 | 8513 | $(apiConfig.button).trigger('click'); |
| 8514 | 8514 | } |
| 8515 | 8515 | |
| 8516 | - toastr.info(`API set to ${text}, trying to connect..`); | |
| 8516 | + const quiet = isTrueBoolean(args?.quiet); | |
| 8517 | + quiet ? jQuery() : toastr.info(`API set to ${text}, trying to connect..`); | |
| 8517 | 8518 | |
| 8518 | 8519 | try { |
| 8519 | 8520 | await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100); |
| 8520 | 8521 | console.log('Connection successful'); |
| 8521 | 8522 | } catch { |
| 8522 | 8523 | console.log('Could not connect after 510 seconds, skipping.'); |
| 8523 | 8524 | } |
| 8525 | + | |
| 8526 | + return ''; | |
| 8524 | 8527 | } |
| 8525 | 8528 | |
| 8526 | 8529 | /** |
| @@ -8979,6 +8982,15 @@ jQuery(async function () { | ||
| 8979 | 8982 | name: 'api', |
| 8980 | 8983 | callback: connectAPISlash, |
| 8981 | 8984 | returns: 'the current API', |
| 8985 | + namedArgumentList: [ | |
| 8986 | + SlashCommandNamedArgument.fromProps({ | |
| 8987 | + name: 'quiet', | |
| 8988 | + description: 'Suppress the toast message on connection', | |
| 8989 | + typeList: [ARGUMENT_TYPE.BOOLEAN], | |
| 8990 | + defaultValue: 'false', | |
| 8991 | + enumList: commonEnumProviders.boolean('trueFalse')(), | |
| 8992 | + }), | |
| 8993 | + ], | |
| 8982 | 8994 | unnamedArgumentList: [ |
| 8983 | 8995 | SlashCommandArgument.fromProps({ |
| 8984 | 8996 | description: 'API to connect to', |
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | import { getStringHash, debounce, waitUntilCondition, extractAllWords, isTrueBoolean } from '../../utils.js'; |
| 2 | 2 | import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync } from '../../extensions.js'; |
| 3 | 3 | import { |
| 4 | 4 | activateSendButtons, |
| @@ -26,6 +26,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js'; | ||
| 26 | 26 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js'; |
| 27 | 27 | import { MacrosParser } from '../../macros.js'; |
| 28 | 28 | import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js'; |
| 29 | +import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; | |
| 29 | 30 | export { MODULE_NAME }; |
| 30 | 31 | |
| 31 | 32 | const MODULE_NAME = '1_memory'; |
| @@ -456,7 +457,12 @@ async function onChatEvent() { | ||
| 456 | 457 | } |
| 457 | 458 | } |
| 458 | 459 | |
| 459 | -async function forceSummarizeChat() { | |
| 460 | +/** | |
| 461 | + * Forces a summary generation for the current chat. | |
| 462 | + * @param {boolean} quiet If an informational toast should be displayed | |
| 463 | + * @returns {Promise<string>} Summarized text | |
| 464 | + */ | |
| 465 | +async function forceSummarizeChat(quiet) { | |
| 460 | 466 | if (extension_settings.memory.source === summary_sources.extras) { |
| 461 | 467 | toastr.warning('Force summarization is not supported for Extras API'); |
| 462 | 468 | return; |
| @@ -471,7 +477,7 @@ async function forceSummarizeChat() { | ||
| 471 | 477 | return ''; |
| 472 | 478 | } |
| 473 | 479 | |
| 474 | 480 | const toast = quiet ? jQuery() : toastr.info('Summarizing chat...', 'Please wait', { timeOut: 0, extendedTimeOut: 0 }); |
| 475 | 481 | const value = extension_settings.memory.source === summary_sources.main |
| 476 | 482 | ? await summarizeChatMain(context, true, skipWIAN) |
| 477 | 483 | : await summarizeChatWebLLM(context, true); |
| @@ -494,9 +500,10 @@ async function forceSummarizeChat() { | ||
| 494 | 500 | async function summarizeCallback(args, text) { |
| 495 | 501 | text = text.trim(); |
| 496 | 502 | |
| 497 | 503 | // Using forceSummarizeChat to summarizeSummarize the current chat if no text provided |
| 498 | 504 | if (!text) { |
| 499 | 505 | returnconst awaitquiet forceSummarizeChat= isTrueBoolean(args.quiet); |
| 506 | + return await forceSummarizeChat(quiet); | |
| 500 | 507 | } |
| 501 | 508 | |
| 502 | 509 | const source = args.source || extension_settings.memory.source; |
| @@ -1005,7 +1012,7 @@ function setupListeners() { | ||
| 1005 | 1012 | $('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput); |
| 1006 | 1013 | $('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput); |
| 1007 | 1014 | $('#memory_prompt').off('click').on('input', onMemoryPromptInput); |
| 1008 | 1015 | $('#memory_force_summarize').off('click').on('click', () => forceSummarizeChat(false)); |
| 1009 | 1016 | $('#memory_template').off('click').on('input', onMemoryTemplateInput); |
| 1010 | 1017 | $('#memory_depth').off('click').on('input', onMemoryDepthInput); |
| 1011 | 1018 | $('#memory_role').off('click').on('input', onMemoryRoleInput); |
| @@ -1055,6 +1062,13 @@ jQuery(async function () { | ||
| 1055 | 1062 | typeList: [ARGUMENT_TYPE.STRING], |
| 1056 | 1063 | defaultValue: '', |
| 1057 | 1064 | }), |
| 1065 | + SlashCommandNamedArgument.fromProps({ | |
| 1066 | + name: 'quiet', | |
| 1067 | + description: 'suppress the toast message when summarizing the chat', | |
| 1068 | + typeList: [ARGUMENT_TYPE.BOOLEAN], | |
| 1069 | + defaultValue: 'false', | |
| 1070 | + enumList: commonEnumProviders.boolean('trueFalse')(), | |
| 1071 | + }), | |
| 1058 | 1072 | ], |
| 1059 | 1073 | unnamedArgumentList: [ |
| 1060 | 1074 | new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''), |