mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-04-02 05:10:14 +02:00
Merge pull request #3542 from SillyTavern/summary-improvements
Assorted summary improvements
This commit is contained in:
commit
e0d1b21006
@ -32,9 +32,6 @@ export { MODULE_NAME };
|
|||||||
|
|
||||||
const MODULE_NAME = '1_memory';
|
const MODULE_NAME = '1_memory';
|
||||||
|
|
||||||
let lastCharacterId = null;
|
|
||||||
let lastGroupId = null;
|
|
||||||
let lastChatId = null;
|
|
||||||
let lastMessageHash = null;
|
let lastMessageHash = null;
|
||||||
let lastMessageId = null;
|
let lastMessageId = null;
|
||||||
let inApiCall = false;
|
let inApiCall = false;
|
||||||
@ -251,7 +248,7 @@ function onSummarySourceChange(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function switchSourceControls(value) {
|
function switchSourceControls(value) {
|
||||||
$('#memory_settings [data-summary-source]').each((_, element) => {
|
$('#summaryExtensionDrawerContents [data-summary-source], #memory_settings [data-summary-source]').each((_, element) => {
|
||||||
const source = element.dataset.summarySource.split(',').map(s => s.trim());
|
const source = element.dataset.summarySource.split(',').map(s => s.trim());
|
||||||
$(element).toggle(source.includes(value));
|
$(element).toggle(source.includes(value));
|
||||||
});
|
});
|
||||||
@ -349,15 +346,6 @@ function onMaxMessagesPerRequestInput() {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveLastValues() {
|
|
||||||
const context = getContext();
|
|
||||||
lastGroupId = context.groupId;
|
|
||||||
lastCharacterId = context.characterId;
|
|
||||||
lastChatId = context.chatId;
|
|
||||||
lastMessageId = context.chat?.length ?? null;
|
|
||||||
lastMessageHash = getStringHash((context.chat.length && context.chat[context.chat.length - 1]['mes']) ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLatestMemoryFromChat(chat) {
|
function getLatestMemoryFromChat(chat) {
|
||||||
if (!Array.isArray(chat) || !chat.length) {
|
if (!Array.isArray(chat) || !chat.length) {
|
||||||
return '';
|
return '';
|
||||||
@ -390,6 +378,12 @@ function getIndexOfLatestChatSummary(chat) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onChatChanged() {
|
||||||
|
const context = getContext();
|
||||||
|
const latestMemory = getLatestMemoryFromChat(context.chat);
|
||||||
|
setMemoryContext(latestMemory, false);
|
||||||
|
}
|
||||||
|
|
||||||
async function onChatEvent() {
|
async function onChatEvent() {
|
||||||
// Module not enabled
|
// Module not enabled
|
||||||
if (extension_settings.memory.source === summary_sources.extras && !modules.includes('summarize')) {
|
if (extension_settings.memory.source === summary_sources.extras && !modules.includes('summarize')) {
|
||||||
@ -401,32 +395,19 @@ async function onChatEvent() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const context = getContext();
|
|
||||||
const chat = context.chat;
|
|
||||||
|
|
||||||
// no characters or group selected
|
|
||||||
if (!context.groupId && context.characterId === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Streaming in-progress
|
// Streaming in-progress
|
||||||
if (streamingProcessor && !streamingProcessor.isFinished) {
|
if (streamingProcessor && !streamingProcessor.isFinished) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chat/character/group changed
|
|
||||||
if ((context.groupId && lastGroupId !== context.groupId) || (context.characterId !== lastCharacterId) || (context.chatId !== lastChatId)) {
|
|
||||||
const latestMemory = getLatestMemoryFromChat(chat);
|
|
||||||
setMemoryContext(latestMemory, false);
|
|
||||||
saveLastValues();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Currently summarizing or frozen state - skip
|
// Currently summarizing or frozen state - skip
|
||||||
if (inApiCall || extension_settings.memory.memoryFrozen) {
|
if (inApiCall || extension_settings.memory.memoryFrozen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const context = getContext();
|
||||||
|
const chat = context.chat;
|
||||||
|
|
||||||
// No new messages - do nothing
|
// No new messages - do nothing
|
||||||
if (chat.length === 0 || (lastMessageId === chat.length && getStringHash(chat[chat.length - 1].mes) === lastMessageHash)) {
|
if (chat.length === 0 || (lastMessageId === chat.length && getStringHash(chat[chat.length - 1].mes) === lastMessageHash)) {
|
||||||
return;
|
return;
|
||||||
@ -449,7 +430,10 @@ async function onChatEvent() {
|
|||||||
|
|
||||||
summarizeChat(context)
|
summarizeChat(context)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
.finally(saveLastValues);
|
.finally(() => {
|
||||||
|
lastMessageId = context.chat?.length ?? null;
|
||||||
|
lastMessageHash = getStringHash((context.chat.length && context.chat[context.chat.length - 1]['mes']) ?? '');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -464,13 +448,7 @@ async function forceSummarizeChat(quiet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
|
|
||||||
const skipWIAN = extension_settings.memory.SkipWIAN;
|
const skipWIAN = extension_settings.memory.SkipWIAN;
|
||||||
console.log(`Skipping WIAN? ${skipWIAN}`);
|
|
||||||
if (!context.chatId) {
|
|
||||||
toastr.warning('No chat selected');
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const toast = quiet ? jQuery() : 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
|
||||||
@ -993,7 +971,7 @@ function doPopout(e) {
|
|||||||
.removeClass('zoomed_avatar')
|
.removeClass('zoomed_avatar')
|
||||||
.addClass('draggable')
|
.addClass('draggable')
|
||||||
.empty();
|
.empty();
|
||||||
const prevSummaryBoxContents = $('#memory_contents').val(); //copy summary box before emptying
|
const prevSummaryBoxContents = $('#memory_contents').val().toString(); //copy summary box before emptying
|
||||||
originalElement.empty();
|
originalElement.empty();
|
||||||
originalElement.html('<div class="flex-container alignitemscenter justifyCenter wide100p"><small>Currently popped out</small></div>');
|
originalElement.html('<div class="flex-container alignitemscenter justifyCenter wide100p"><small>Currently popped out</small></div>');
|
||||||
newElement.append(controlBarHtml).append(originalHTMLClone);
|
newElement.append(controlBarHtml).append(originalHTMLClone);
|
||||||
@ -1013,7 +991,7 @@ function doPopout(e) {
|
|||||||
const summaryPopoutHTML = $('#summaryExtensionDrawerContents');
|
const summaryPopoutHTML = $('#summaryExtensionDrawerContents');
|
||||||
$('#summaryExtensionPopout').fadeOut(animation_duration, () => {
|
$('#summaryExtensionPopout').fadeOut(animation_duration, () => {
|
||||||
originalElement.empty();
|
originalElement.empty();
|
||||||
originalElement.html(summaryPopoutHTML);
|
originalElement.append(summaryPopoutHTML);
|
||||||
$('#summaryExtensionPopout').remove();
|
$('#summaryExtensionPopout').remove();
|
||||||
});
|
});
|
||||||
loadSettings();
|
loadSettings();
|
||||||
@ -1027,31 +1005,30 @@ function doPopout(e) {
|
|||||||
function setupListeners() {
|
function setupListeners() {
|
||||||
//setup shared listeners for popout and regular ext menu
|
//setup shared listeners for popout and regular ext menu
|
||||||
$('#memory_restore').off('click').on('click', onMemoryRestoreClick);
|
$('#memory_restore').off('click').on('click', onMemoryRestoreClick);
|
||||||
$('#memory_contents').off('click').on('input', onMemoryContentInput);
|
$('#memory_contents').off('input').on('input', onMemoryContentInput);
|
||||||
$('#memory_frozen').off('click').on('input', onMemoryFrozenInput);
|
$('#memory_frozen').off('input').on('input', onMemoryFrozenInput);
|
||||||
$('#memory_skipWIAN').off('click').on('input', onMemorySkipWIANInput);
|
$('#memory_skipWIAN').off('input').on('input', onMemorySkipWIANInput);
|
||||||
$('#summary_source').off('click').on('change', onSummarySourceChange);
|
$('#summary_source').off('change').on('change', onSummarySourceChange);
|
||||||
$('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput);
|
$('#memory_prompt_words').off('input').on('input', onMemoryPromptWordsInput);
|
||||||
$('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput);
|
$('#memory_prompt_interval').off('input').on('input', onMemoryPromptIntervalInput);
|
||||||
$('#memory_prompt').off('click').on('input', onMemoryPromptInput);
|
$('#memory_prompt').off('input').on('input', onMemoryPromptInput);
|
||||||
$('#memory_force_summarize').off('click').on('click', () => forceSummarizeChat(false));
|
$('#memory_force_summarize').off('click').on('click', () => forceSummarizeChat(false));
|
||||||
$('#memory_template').off('click').on('input', onMemoryTemplateInput);
|
$('#memory_template').off('input').on('input', onMemoryTemplateInput);
|
||||||
$('#memory_depth').off('click').on('input', onMemoryDepthInput);
|
$('#memory_depth').off('input').on('input', onMemoryDepthInput);
|
||||||
$('#memory_role').off('click').on('input', onMemoryRoleInput);
|
$('#memory_role').off('input').on('input', onMemoryRoleInput);
|
||||||
$('input[name="memory_position"]').off('click').on('change', onMemoryPositionChange);
|
$('input[name="memory_position"]').off('change').on('change', onMemoryPositionChange);
|
||||||
$('#memory_prompt_words_force').off('click').on('input', onMemoryPromptWordsForceInput);
|
$('#memory_prompt_words_force').off('input').on('input', onMemoryPromptWordsForceInput);
|
||||||
$('#memory_prompt_builder_default').off('click').on('input', onMemoryPromptBuilderInput);
|
$('#memory_prompt_builder_default').off('input').on('input', onMemoryPromptBuilderInput);
|
||||||
$('#memory_prompt_builder_raw_blocking').off('click').on('input', onMemoryPromptBuilderInput);
|
$('#memory_prompt_builder_raw_blocking').off('input').on('input', onMemoryPromptBuilderInput);
|
||||||
$('#memory_prompt_builder_raw_non_blocking').off('click').on('input', onMemoryPromptBuilderInput);
|
$('#memory_prompt_builder_raw_non_blocking').off('input').on('input', onMemoryPromptBuilderInput);
|
||||||
$('#memory_prompt_restore').off('click').on('click', onMemoryPromptRestoreClick);
|
$('#memory_prompt_restore').off('click').on('click', onMemoryPromptRestoreClick);
|
||||||
$('#memory_prompt_interval_auto').off('click').on('click', onPromptIntervalAutoClick);
|
$('#memory_prompt_interval_auto').off('click').on('click', onPromptIntervalAutoClick);
|
||||||
$('#memory_prompt_words_auto').off('click').on('click', onPromptForceWordsAutoClick);
|
$('#memory_prompt_words_auto').off('click').on('click', onPromptForceWordsAutoClick);
|
||||||
$('#memory_override_response_length').off('click').on('input', onOverrideResponseLengthInput);
|
$('#memory_override_response_length').off('input').on('input', onOverrideResponseLengthInput);
|
||||||
$('#memory_max_messages_per_request').off('click').on('input', onMaxMessagesPerRequestInput);
|
$('#memory_max_messages_per_request').off('input').on('input', onMaxMessagesPerRequestInput);
|
||||||
$('#memory_include_wi_scan').off('input').on('input', onMemoryIncludeWIScanInput);
|
$('#memory_include_wi_scan').off('input').on('input', onMemoryIncludeWIScanInput);
|
||||||
$('#summarySettingsBlockToggle').off('click').on('click', function () {
|
$('#summarySettingsBlockToggle').off('click').on('click', function () {
|
||||||
console.log('saw settings button click');
|
$('#summarySettingsBlock').slideToggle(200, 'swing');
|
||||||
$('#summarySettingsBlock').slideToggle(200, 'swing'); //toggleClass("hidden");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1068,11 +1045,11 @@ jQuery(async function () {
|
|||||||
|
|
||||||
await addExtensionControls();
|
await addExtensionControls();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
eventSource.on(event_types.CHAT_CHANGED, onChatChanged);
|
||||||
eventSource.makeLast(event_types.CHARACTER_MESSAGE_RENDERED, onChatEvent);
|
eventSource.makeLast(event_types.CHARACTER_MESSAGE_RENDERED, onChatEvent);
|
||||||
eventSource.on(event_types.MESSAGE_DELETED, onChatEvent);
|
for (const event of [event_types.MESSAGE_DELETED, event_types.MESSAGE_UPDATED, event_types.MESSAGE_SWIPED]) {
|
||||||
eventSource.on(event_types.MESSAGE_EDITED, onChatEvent);
|
eventSource.on(event, onChatEvent);
|
||||||
eventSource.on(event_types.MESSAGE_SWIPED, onChatEvent);
|
}
|
||||||
eventSource.on(event_types.CHAT_CHANGED, onChatEvent);
|
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'summarize',
|
name: 'summarize',
|
||||||
callback: summarizeCallback,
|
callback: summarizeCallback,
|
||||||
|
@ -10,16 +10,18 @@
|
|||||||
<div class="inline-drawer-content">
|
<div class="inline-drawer-content">
|
||||||
<div id="summaryExtensionDrawerContents">
|
<div id="summaryExtensionDrawerContents">
|
||||||
<label for="summary_source" data-i18n="ext_sum_with">Summarize with:</label>
|
<label for="summary_source" data-i18n="ext_sum_with">Summarize with:</label>
|
||||||
<select id="summary_source">
|
<select id="summary_source" class="text_pole">
|
||||||
<option value="main" data-i18n="ext_sum_main_api">Main API</option>
|
<option value="main" data-i18n="ext_sum_main_api">Main API</option>
|
||||||
<option value="extras">Extras API (deprecated)</option>
|
<option value="extras">Extras API (deprecated)</option>
|
||||||
<option value="webllm" data-i18n="ext_sum_webllm">WebLLM Extension</option>
|
<option value="webllm" data-i18n="ext_sum_webllm">WebLLM Extension</option>
|
||||||
</select><br>
|
</select><br>
|
||||||
|
|
||||||
<div class="flex-container justifyspacebetween alignitemscenter">
|
<div class="flex-container justifyspacebetween alignitemscenter">
|
||||||
<span class="flex1" data-i18n="ext_sum_current_summary">Current summary:</span>
|
<span data-i18n="ext_sum_current_summary">Current summary:</span>
|
||||||
<div id="memory_restore" class="menu_button flex1 margin0" data-i18n="[title]ext_sum_restore_tip" title="Restore a previous summary; use repeatedly to clear summarization state for this chat.">
|
<i class="editor_maximize fa-solid fa-maximize right_menu_button" data-for="memory_contents" title="Expand the editor" data-i18n="[title]Expand the editor"></i>
|
||||||
<span data-i18n="ext_sum_restore_previous">Restore Previous</span>
|
<span class="flex1"> </span>
|
||||||
|
<div id="memory_restore" class="menu_button margin0" data-i18n="[title]ext_sum_restore_tip" title="Restore a previous summary; use repeatedly to clear summarization state for this chat.">
|
||||||
|
<small data-i18n="ext_sum_restore_previous">Restore Previous</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -3,9 +3,13 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
#memory_settings textarea {
|
#memory_contents {
|
||||||
font-size: calc(var(--mainFontSize) * 0.9);
|
field-sizing: content;
|
||||||
line-height: 1.2;
|
max-height: 50dvh;
|
||||||
|
}
|
||||||
|
|
||||||
|
#memory_restore {
|
||||||
|
width: max-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
label[for="memory_frozen"],
|
label[for="memory_frozen"],
|
||||||
@ -35,3 +39,9 @@ label[for="memory_frozen"] input {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
row-gap: 5px;
|
row-gap: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#summaryExtensionPopout {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding-top: 25px;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user