mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
@ -242,7 +242,7 @@ import { DragAndDropHandler } from './scripts/dragdrop.js';
|
|||||||
import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js';
|
import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js';
|
||||||
import { initDynamicStyles } from './scripts/dynamic-styles.js';
|
import { initDynamicStyles } from './scripts/dynamic-styles.js';
|
||||||
import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.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
|
//exporting functions and vars for mods
|
||||||
export {
|
export {
|
||||||
@ -8465,7 +8465,7 @@ async function disableInstructCallback() {
|
|||||||
/**
|
/**
|
||||||
* @param {string} text API name
|
* @param {string} text API name
|
||||||
*/
|
*/
|
||||||
async function connectAPISlash(_, text) {
|
async function connectAPISlash(args, text) {
|
||||||
if (!text.trim()) {
|
if (!text.trim()) {
|
||||||
for (const [key, config] of Object.entries(CONNECT_API_MAP)) {
|
for (const [key, config] of Object.entries(CONNECT_API_MAP)) {
|
||||||
if (config.selected !== main_api) continue;
|
if (config.selected !== main_api) continue;
|
||||||
@ -8493,7 +8493,7 @@ async function connectAPISlash(_, text) {
|
|||||||
const apiConfig = CONNECT_API_MAP[text.toLowerCase()];
|
const apiConfig = CONNECT_API_MAP[text.toLowerCase()];
|
||||||
if (!apiConfig) {
|
if (!apiConfig) {
|
||||||
toastr.error(`Error: ${text} is not a valid API`);
|
toastr.error(`Error: ${text} is not a valid API`);
|
||||||
return;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true);
|
$(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true);
|
||||||
@ -8513,14 +8513,17 @@ async function connectAPISlash(_, text) {
|
|||||||
$(apiConfig.button).trigger('click');
|
$(apiConfig.button).trigger('click');
|
||||||
}
|
}
|
||||||
|
|
||||||
toastr.info(`API set to ${text}, trying to connect..`);
|
const quiet = isTrueBoolean(args?.quiet);
|
||||||
|
quiet ? jQuery() : toastr.info(`API set to ${text}, trying to connect..`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100);
|
await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100);
|
||||||
console.log('Connection successful');
|
console.log('Connection successful');
|
||||||
} catch {
|
} catch {
|
||||||
console.log('Could not connect after 5 seconds, skipping.');
|
console.log('Could not connect after 10 seconds, skipping.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8979,6 +8982,15 @@ jQuery(async function () {
|
|||||||
name: 'api',
|
name: 'api',
|
||||||
callback: connectAPISlash,
|
callback: connectAPISlash,
|
||||||
returns: 'the current API',
|
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: [
|
unnamedArgumentList: [
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
description: 'API to connect to',
|
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 { getContext, getApiUrl, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync } from '../../extensions.js';
|
||||||
import {
|
import {
|
||||||
activateSendButtons,
|
activateSendButtons,
|
||||||
@ -26,6 +26,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
|||||||
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
|
||||||
import { MacrosParser } from '../../macros.js';
|
import { MacrosParser } from '../../macros.js';
|
||||||
import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js';
|
import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js';
|
||||||
|
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = '1_memory';
|
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) {
|
if (extension_settings.memory.source === summary_sources.extras) {
|
||||||
toastr.warning('Force summarization is not supported for Extras API');
|
toastr.warning('Force summarization is not supported for Extras API');
|
||||||
return;
|
return;
|
||||||
@ -471,7 +477,7 @@ async function forceSummarizeChat() {
|
|||||||
return '';
|
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
|
const value = extension_settings.memory.source === summary_sources.main
|
||||||
? await summarizeChatMain(context, true, skipWIAN)
|
? await summarizeChatMain(context, true, skipWIAN)
|
||||||
: await summarizeChatWebLLM(context, true);
|
: await summarizeChatWebLLM(context, true);
|
||||||
@ -494,9 +500,10 @@ async function forceSummarizeChat() {
|
|||||||
async function summarizeCallback(args, text) {
|
async function summarizeCallback(args, text) {
|
||||||
text = text.trim();
|
text = text.trim();
|
||||||
|
|
||||||
// Using forceSummarizeChat to summarize the current chat
|
// Summarize the current chat if no text provided
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return await forceSummarizeChat();
|
const quiet = isTrueBoolean(args.quiet);
|
||||||
|
return await forceSummarizeChat(quiet);
|
||||||
}
|
}
|
||||||
|
|
||||||
const source = args.source || extension_settings.memory.source;
|
const source = args.source || extension_settings.memory.source;
|
||||||
@ -1005,7 +1012,7 @@ function setupListeners() {
|
|||||||
$('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput);
|
$('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput);
|
||||||
$('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput);
|
$('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput);
|
||||||
$('#memory_prompt').off('click').on('input', onMemoryPromptInput);
|
$('#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_template').off('click').on('input', onMemoryTemplateInput);
|
||||||
$('#memory_depth').off('click').on('input', onMemoryDepthInput);
|
$('#memory_depth').off('click').on('input', onMemoryDepthInput);
|
||||||
$('#memory_role').off('click').on('input', onMemoryRoleInput);
|
$('#memory_role').off('click').on('input', onMemoryRoleInput);
|
||||||
@ -1055,6 +1062,13 @@ jQuery(async function () {
|
|||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
defaultValue: '',
|
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: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''),
|
new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''),
|
||||||
|
Reference in New Issue
Block a user