Merge pull request #2691 from SillyTavern/quiet Add quiet flags to /api and /summarize
Signed| @@ -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 { |
| @@ -8475,7 +8475,7 @@ async function disableInstructCallback() { | ||
| 8475 | 8475 | /** |
| 8476 | 8476 | * @param {string} text API name |
| 8477 | 8477 | */ |
| 8478 | 8478 | async function connectAPISlash(_args, text) { |
| 8479 | 8479 | if (!text.trim()) { |
| 8480 | 8480 | for (const [key, config] of Object.entries(CONNECT_API_MAP)) { |
| 8481 | 8481 | if (config.selected !== main_api) continue; |
| @@ -8498,12 +8498,15 @@ async function connectAPISlash(_, text) { | ||
| 8498 | 8498 | |
| 8499 | 8499 | return key; |
| 8500 | 8500 | } |
| 8501 | + | |
| 8502 | + console.error('FIXME: The current API is not in the API map'); | |
| 8503 | + return ''; | |
| 8501 | 8504 | } |
| 8502 | 8505 | |
| 8503 | 8506 | const apiConfig = CONNECT_API_MAP[text.toLowerCase()]; |
| 8504 | 8507 | if (!apiConfig) { |
| 8505 | 8508 | toastr.error(`Error: ${text} is not a valid API`); |
| 8506 | 8509 | return ''; |
| 8507 | 8510 | } |
| 8508 | 8511 | |
| 8509 | 8512 | $(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true); |
| @@ -8523,14 +8526,18 @@ async function connectAPISlash(_, text) { | ||
| 8523 | 8526 | $(apiConfig.button).trigger('click'); |
| 8524 | 8527 | } |
| 8525 | 8528 | |
| 8526 | - toastr.info(`API set to ${text}, trying to connect..`); | |
| 8529 | + const quiet = isTrueBoolean(args?.quiet); | |
| 8530 | + const toast = quiet ? jQuery() : toastr.info(`API set to ${text}, trying to connect..`); | |
| 8527 | 8531 | |
| 8528 | 8532 | try { |
| 8529 | 8533 | await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100); |
| 8530 | 8534 | console.log('Connection successful'); |
| 8531 | 8535 | } catch { |
| 8532 | 8536 | console.log('Could not connect after 510 seconds, skipping.'); |
| 8533 | 8537 | } |
| 8538 | + | |
| 8539 | + toastr.clear(toast); | |
| 8540 | + return text; | |
| 8534 | 8541 | } |
| 8535 | 8542 | |
| 8536 | 8543 | /** |
| @@ -8989,6 +8996,15 @@ jQuery(async function () { | ||
| 8989 | 8996 | name: 'api', |
| 8990 | 8997 | callback: connectAPISlash, |
| 8991 | 8998 | returns: 'the current API', |
| 8999 | + namedArgumentList: [ | |
| 9000 | + SlashCommandNamedArgument.fromProps({ | |
| 9001 | + name: 'quiet', | |
| 9002 | + description: 'Suppress the toast message on connection', | |
| 9003 | + typeList: [ARGUMENT_TYPE.BOOLEAN], | |
| 9004 | + defaultValue: 'false', | |
| 9005 | + enumList: commonEnumProviders.boolean('trueFalse')(), | |
| 9006 | + }), | |
| 9007 | + ], | |
| 8992 | 9008 | unnamedArgumentList: [ |
| 8993 | 9009 | SlashCommandArgument.fromProps({ |
| 8994 | 9010 | 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, ''), |