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 | import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js'; | 242 | import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js'; |
| 243 | import { initDynamicStyles } from './scripts/dynamic-styles.js'; | 243 | import { initDynamicStyles } from './scripts/dynamic-styles.js'; |
| 244 | import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js'; | 244 | import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js'; |
| 245 | import { enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js'; | 245 | import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 246 | 246 | ||
| 247 | //exporting functions and vars for mods | 247 | //exporting functions and vars for mods |
| 248 | export { | 248 | export { |
| @@ -8475,7 +8475,7 @@ async function disableInstructCallback() { | |||
| 8475 | /** | 8475 | /** |
| 8476 | * @param {string} text API name | 8476 | * @param {string} text API name |
| 8477 | */ | 8477 | */ |
| 8478 | async function connectAPISlash(_, text) { | 8478 | async function connectAPISlash(args, text) { |
| 8479 | if (!text.trim()) { | 8479 | if (!text.trim()) { |
| 8480 | for (const [key, config] of Object.entries(CONNECT_API_MAP)) { | 8480 | for (const [key, config] of Object.entries(CONNECT_API_MAP)) { |
| 8481 | if (config.selected !== main_api) continue; | 8481 | if (config.selected !== main_api) continue; |
| @@ -8498,12 +8498,15 @@ async function connectAPISlash(_, text) { | |||
| 8498 | 8498 | ||
| 8499 | return key; | 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 | const apiConfig = CONNECT_API_MAP[text.toLowerCase()]; | 8506 | const apiConfig = CONNECT_API_MAP[text.toLowerCase()]; |
| 8504 | if (!apiConfig) { | 8507 | if (!apiConfig) { |
| 8505 | toastr.error(`Error: ${text} is not a valid API`); | 8508 | toastr.error(`Error: ${text} is not a valid API`); |
| 8506 | return; | 8509 | return ''; |
| 8507 | } | 8510 | } |
| 8508 | 8511 | ||
| 8509 | $(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true); | 8512 | $(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true); |
| @@ -8523,14 +8526,18 @@ async function connectAPISlash(_, text) { | |||
| 8523 | $(apiConfig.button).trigger('click'); | 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 | try { | 8532 | try { |
| 8529 | await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100); | 8533 | await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100); |
| 8530 | console.log('Connection successful'); | 8534 | console.log('Connection successful'); |
| 8531 | } catch { | 8535 | } catch { |
| 8532 | console.log('Could not connect after 5 seconds, skipping.'); | 8536 | console.log('Could not connect after 10 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 | name: 'api', | 8996 | name: 'api', |
| 8990 | callback: connectAPISlash, | 8997 | callback: connectAPISlash, |
| 8991 | returns: 'the current API', | 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 | unnamedArgumentList: [ | 9008 | unnamedArgumentList: [ |
| 8993 | SlashCommandArgument.fromProps({ | 9009 | SlashCommandArgument.fromProps({ |
| 8994 | description: 'API to connect to', | 9010 | description: 'API to connect to', |
| @@ -1,4 +1,4 @@ | |||
| 1 | import { getStringHash, debounce, waitUntilCondition, extractAllWords } from '../../utils.js'; | 1 | import { getStringHash, debounce, waitUntilCondition, extractAllWords, isTrueBoolean } from '../../utils.js'; |
| 2 | import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync } from '../../extensions.js'; | 2 | import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync } from '../../extensions.js'; |
| 3 | import { | 3 | import { |
| 4 | activateSendButtons, | 4 | activateSendButtons, |
| @@ -26,6 +26,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js'; | |||
| 26 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js'; | 26 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js'; |
| 27 | import { MacrosParser } from '../../macros.js'; | 27 | import { MacrosParser } from '../../macros.js'; |
| 28 | import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js'; | 28 | import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js'; |
| 29 | import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; | ||
| 29 | export { MODULE_NAME }; | 30 | export { MODULE_NAME }; |
| 30 | 31 | ||
| 31 | const MODULE_NAME = '1_memory'; | 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 | if (extension_settings.memory.source === summary_sources.extras) { | 466 | if (extension_settings.memory.source === summary_sources.extras) { |
| 461 | toastr.warning('Force summarization is not supported for Extras API'); | 467 | toastr.warning('Force summarization is not supported for Extras API'); |
| 462 | return; | 468 | return; |
| @@ -471,7 +477,7 @@ async function forceSummarizeChat() { | |||
| 471 | return ''; | 477 | return ''; |
| 472 | } | 478 | } |
| 473 | 479 | ||
| 474 | const toast = toastr.info('Summarizing chat...', 'Please wait', { timeOut: 0, extendedTimeOut: 0 }); | 480 | const toast = quiet ? jQuery() : toastr.info('Summarizing chat...', 'Please wait', { timeOut: 0, extendedTimeOut: 0 }); |
| 475 | const value = extension_settings.memory.source === summary_sources.main | 481 | const value = extension_settings.memory.source === summary_sources.main |
| 476 | ? await summarizeChatMain(context, true, skipWIAN) | 482 | ? await summarizeChatMain(context, true, skipWIAN) |
| 477 | : await summarizeChatWebLLM(context, true); | 483 | : await summarizeChatWebLLM(context, true); |
| @@ -494,9 +500,10 @@ async function forceSummarizeChat() { | |||
| 494 | async function summarizeCallback(args, text) { | 500 | async function summarizeCallback(args, text) { |
| 495 | text = text.trim(); | 501 | text = text.trim(); |
| 496 | 502 | ||
| 497 | // Using forceSummarizeChat to summarize the current chat | 503 | // Summarize the current chat if no text provided |
| 498 | if (!text) { | 504 | if (!text) { |
| 499 | return await forceSummarizeChat(); | 505 | const quiet = isTrueBoolean(args.quiet); |
| 506 | return await forceSummarizeChat(quiet); | ||
| 500 | } | 507 | } |
| 501 | 508 | ||
| 502 | const source = args.source || extension_settings.memory.source; | 509 | const source = args.source || extension_settings.memory.source; |
| @@ -1005,7 +1012,7 @@ function setupListeners() { | |||
| 1005 | $('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput); | 1012 | $('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput); |
| 1006 | $('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput); | 1013 | $('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput); |
| 1007 | $('#memory_prompt').off('click').on('input', onMemoryPromptInput); | 1014 | $('#memory_prompt').off('click').on('input', onMemoryPromptInput); |
| 1008 | $('#memory_force_summarize').off('click').on('click', forceSummarizeChat); | 1015 | $('#memory_force_summarize').off('click').on('click', () => forceSummarizeChat(false)); |
| 1009 | $('#memory_template').off('click').on('input', onMemoryTemplateInput); | 1016 | $('#memory_template').off('click').on('input', onMemoryTemplateInput); |
| 1010 | $('#memory_depth').off('click').on('input', onMemoryDepthInput); | 1017 | $('#memory_depth').off('click').on('input', onMemoryDepthInput); |
| 1011 | $('#memory_role').off('click').on('input', onMemoryRoleInput); | 1018 | $('#memory_role').off('click').on('input', onMemoryRoleInput); |
| @@ -1055,6 +1062,13 @@ jQuery(async function () { | |||
| 1055 | typeList: [ARGUMENT_TYPE.STRING], | 1062 | typeList: [ARGUMENT_TYPE.STRING], |
| 1056 | defaultValue: '', | 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 | unnamedArgumentList: [ | 1073 | unnamedArgumentList: [ |
| 1060 | new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''), | 1074 | new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''), |