mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-09 08:30:13 +01:00
Merge pull request #2691 from SillyTavern/quiet
Add quiet flags to /api and /summarize
This commit is contained in:
commit
e4d012e49d
@ -242,7 +242,7 @@ import { DragAndDropHandler } from './scripts/dragdrop.js';
|
||||
import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js';
|
||||
import { initDynamicStyles } from './scripts/dynamic-styles.js';
|
||||
import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js';
|
||||
import { enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||
import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||
|
||||
//exporting functions and vars for mods
|
||||
export {
|
||||
@ -8475,7 +8475,7 @@ async function disableInstructCallback() {
|
||||
/**
|
||||
* @param {string} text API name
|
||||
*/
|
||||
async function connectAPISlash(_, text) {
|
||||
async function connectAPISlash(args, text) {
|
||||
if (!text.trim()) {
|
||||
for (const [key, config] of Object.entries(CONNECT_API_MAP)) {
|
||||
if (config.selected !== main_api) continue;
|
||||
@ -8498,12 +8498,15 @@ async function connectAPISlash(_, text) {
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
console.error('FIXME: The current API is not in the API map');
|
||||
return '';
|
||||
}
|
||||
|
||||
const apiConfig = CONNECT_API_MAP[text.toLowerCase()];
|
||||
if (!apiConfig) {
|
||||
toastr.error(`Error: ${text} is not a valid API`);
|
||||
return;
|
||||
return '';
|
||||
}
|
||||
|
||||
$(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true);
|
||||
@ -8523,14 +8526,18 @@ async function connectAPISlash(_, text) {
|
||||
$(apiConfig.button).trigger('click');
|
||||
}
|
||||
|
||||
toastr.info(`API set to ${text}, trying to connect..`);
|
||||
const quiet = isTrueBoolean(args?.quiet);
|
||||
const toast = quiet ? jQuery() : toastr.info(`API set to ${text}, trying to connect..`);
|
||||
|
||||
try {
|
||||
await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100);
|
||||
console.log('Connection successful');
|
||||
} catch {
|
||||
console.log('Could not connect after 5 seconds, skipping.');
|
||||
console.log('Could not connect after 10 seconds, skipping.');
|
||||
}
|
||||
|
||||
toastr.clear(toast);
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -8989,6 +8996,15 @@ jQuery(async function () {
|
||||
name: 'api',
|
||||
callback: connectAPISlash,
|
||||
returns: 'the current API',
|
||||
namedArgumentList: [
|
||||
SlashCommandNamedArgument.fromProps({
|
||||
name: 'quiet',
|
||||
description: 'Suppress the toast message on connection',
|
||||
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||
defaultValue: 'false',
|
||||
enumList: commonEnumProviders.boolean('trueFalse')(),
|
||||
}),
|
||||
],
|
||||
unnamedArgumentList: [
|
||||
SlashCommandArgument.fromProps({
|
||||
description: 'API to connect to',
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getStringHash, debounce, waitUntilCondition, extractAllWords } from '../../utils.js';
|
||||
import { getStringHash, debounce, waitUntilCondition, extractAllWords, isTrueBoolean } from '../../utils.js';
|
||||
import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync } from '../../extensions.js';
|
||||
import {
|
||||
activateSendButtons,
|
||||
@ -26,6 +26,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
||||
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
||||
import { MacrosParser } from '../../macros.js';
|
||||
import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js';
|
||||
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||
export { MODULE_NAME };
|
||||
|
||||
const MODULE_NAME = '1_memory';
|
||||
@ -456,7 +457,12 @@ async function onChatEvent() {
|
||||
}
|
||||
}
|
||||
|
||||
async function forceSummarizeChat() {
|
||||
/**
|
||||
* Forces a summary generation for the current chat.
|
||||
* @param {boolean} quiet If an informational toast should be displayed
|
||||
* @returns {Promise<string>} Summarized text
|
||||
*/
|
||||
async function forceSummarizeChat(quiet) {
|
||||
if (extension_settings.memory.source === summary_sources.extras) {
|
||||
toastr.warning('Force summarization is not supported for Extras API');
|
||||
return;
|
||||
@ -471,7 +477,7 @@ async function forceSummarizeChat() {
|
||||
return '';
|
||||
}
|
||||
|
||||
const toast = toastr.info('Summarizing chat...', 'Please wait', { timeOut: 0, extendedTimeOut: 0 });
|
||||
const toast = quiet ? jQuery() : toastr.info('Summarizing chat...', 'Please wait', { timeOut: 0, extendedTimeOut: 0 });
|
||||
const value = extension_settings.memory.source === summary_sources.main
|
||||
? await summarizeChatMain(context, true, skipWIAN)
|
||||
: await summarizeChatWebLLM(context, true);
|
||||
@ -494,9 +500,10 @@ async function forceSummarizeChat() {
|
||||
async function summarizeCallback(args, text) {
|
||||
text = text.trim();
|
||||
|
||||
// Using forceSummarizeChat to summarize the current chat
|
||||
// Summarize the current chat if no text provided
|
||||
if (!text) {
|
||||
return await forceSummarizeChat();
|
||||
const quiet = isTrueBoolean(args.quiet);
|
||||
return await forceSummarizeChat(quiet);
|
||||
}
|
||||
|
||||
const source = args.source || extension_settings.memory.source;
|
||||
@ -1005,7 +1012,7 @@ function setupListeners() {
|
||||
$('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput);
|
||||
$('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput);
|
||||
$('#memory_prompt').off('click').on('input', onMemoryPromptInput);
|
||||
$('#memory_force_summarize').off('click').on('click', forceSummarizeChat);
|
||||
$('#memory_force_summarize').off('click').on('click', () => forceSummarizeChat(false));
|
||||
$('#memory_template').off('click').on('input', onMemoryTemplateInput);
|
||||
$('#memory_depth').off('click').on('input', onMemoryDepthInput);
|
||||
$('#memory_role').off('click').on('input', onMemoryRoleInput);
|
||||
@ -1055,6 +1062,13 @@ jQuery(async function () {
|
||||
typeList: [ARGUMENT_TYPE.STRING],
|
||||
defaultValue: '',
|
||||
}),
|
||||
SlashCommandNamedArgument.fromProps({
|
||||
name: 'quiet',
|
||||
description: 'suppress the toast message when summarizing the chat',
|
||||
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||
defaultValue: 'false',
|
||||
enumList: commonEnumProviders.boolean('trueFalse')(),
|
||||
}),
|
||||
],
|
||||
unnamedArgumentList: [
|
||||
new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''),
|
||||
|
Loading…
x
Reference in New Issue
Block a user