Debounce manager changes

This commit is contained in:
Cohee 2023-08-13 18:43:17 +03:00
parent 9b8d069e3b
commit c0bc425c8b
4 changed files with 19 additions and 37 deletions

View File

@ -3743,33 +3743,6 @@
</div>
</div>
</div>
<div id="shadow_select_chat_popup">
<div id="select_chat_popup">
<div id="select_chat_import"> <!-- import chat popup header -->
<div id="chat_import_button" class="fa-solid fa-file-arrow-up menu_button"></div>
<div id="selectChatPopupHeaderText" class="TxtLrgBoldCenter">
<span id="ChatHistoryCharName"></span>
<br>
Chat History
<a href="/notes/10" class="notes-link" target="_blank"><span class="note-link-span">?</span></a>
</div>
<form id="form_import_chat" action="javascript:void(null);" method="post" enctype="multipart/form-data" style="display: none;">
<input type="file" id="chat_import_file" accept=".json, .jsonl" name="avatar">
<input id="chat_import_file_type" name="file_type" class="text_pole" maxlength="999" size="2" value="" autocomplete="off" style="display: none;">
<input id="chat_import_avatar_url" name="avatar_url" class="text_pole" maxlength="999" size="2" value="" autocomplete="off" style="display: none;">
<input id="chat_import_character_name" name="character_name" class="text_pole" maxlength="999" size="2" value="" autocomplete="off" style="display: none;">
</form>
<div id="select_chat_cross" class="fa-solid fa-circle-xmark" alt="Close Past Chat Popup"></div>
</div>
<div id="select_chat_div">
</div>
<div id="load_select_chat_div">
<div class="fa-solid fa-hourglass fa-spin"></div>
</div>
</div>
</div>
<div id="message_template" class="template_element">
<div class="mes" mesid="" ch_name="" is_user="" is_system="" bookmark_link="">

View File

@ -2336,7 +2336,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
if (true === dryRun ||
(online_status != 'no_connection' && this_chid != undefined && this_chid !== 'invalid-safety-id')) {
let textareaText;
if (type !== 'regenerate' && type !== "swipe" && type !== 'quiet' && !isImpersonate) {
if (type !== 'regenerate' && type !== "swipe" && type !== 'quiet' && !isImpersonate && !dryRun) {
is_send_press = true;
textareaText = $("#send_textarea").val();
$("#send_textarea").val('').trigger('input');
@ -2345,7 +2345,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
if (chat.length && chat[chat.length - 1]['is_user']) {
//do nothing? why does this check exist?
}
else if (type !== 'quiet' && type !== "swipe" && !isImpersonate) {
else if (type !== 'quiet' && type !== "swipe" && !isImpersonate && !dryRun) {
chat.length = chat.length - 1;
count_view_mes -= 1;
$('#chat').children().last().hide(500, function () {

View File

@ -1,6 +1,7 @@
import {callPopup, event_types, eventSource, substituteParams} from "../script.js";
import {TokenHandler} from "./openai.js";
import {power_user} from "./power-user.js";
import { debounce } from "./utils.js";
/**
* Register migrations for the prompt manager when settings are loaded or an Open AI preset is loaded.
@ -228,6 +229,9 @@ function PromptManagerModule() {
/** Character reset button click*/
this.handleCharacterReset = () => {};
/** Debounced version of render */
this.renderDebounced = debounce(this.render.bind(this), 1000);
}
/**
@ -501,9 +505,9 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
}
// Re-render when chat history changes.
eventSource.on(event_types.MESSAGE_DELETED, () => this.render());
eventSource.on(event_types.MESSAGE_EDITED, () => this.render());
eventSource.on(event_types.MESSAGE_RECEIVED, () => this.render());
eventSource.on(event_types.MESSAGE_DELETED, () => this.renderDebounced());
eventSource.on(event_types.MESSAGE_EDITED, () => this.renderDebounced());
eventSource.on(event_types.MESSAGE_RECEIVED, () => this.renderDebounced());
// Re-render when chatcompletion settings change
eventSource.on(event_types.CHATCOMPLETION_SOURCE_CHANGED, () => this.render());
@ -518,7 +522,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
// Re-render when the character gets edited.
eventSource.on(event_types.CHARACTER_EDITED, (event) => {
this.handleCharacterUpdated(event);
this.saveServiceSettings().then(() => this.render());
this.saveServiceSettings().then(() => this.renderDebounced());
})
// Re-render when the group changes.
@ -536,11 +540,11 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
// Trigger re-render when token settings are changed
document.getElementById('openai_max_context').addEventListener('change', (event) => {
this.serviceSettings.openai_max_context = event.target.value;
if (this.activeCharacter) this.render();
if (this.activeCharacter) this.renderDebounced();
});
document.getElementById('openai_max_tokens').addEventListener('change', (event) => {
if (this.activeCharacter) this.render();
if (this.activeCharacter) this.renderDebounced();
});
// Prepare prompt edit form buttons
@ -567,7 +571,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
});
// Re-render prompt manager on world settings update
eventSource.on(event_types.WORLDINFO_SETTINGS_UPDATED, () => this.render());
eventSource.on(event_types.WORLDINFO_SETTINGS_UPDATED, () => this.renderDebounced());
this.log('Initialized')
};

View File

@ -1,5 +1,5 @@
import { callPopup, cancelTtsPlay, eventSource, event_types, isMultigenEnabled, is_send_press, saveSettingsDebounced } from '../../../script.js'
import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext } from '../../extensions.js'
import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules } from '../../extensions.js'
import { escapeRegex, getStringHash } from '../../utils.js'
import { EdgeTtsProvider } from './edge.js'
import { ElevenLabsTtsProvider } from './elevenlabs.js'
@ -166,6 +166,11 @@ async function moduleWorker() {
}
function talkingAnimation(switchValue) {
if (!modules.includes('talkinghead')) {
console.debug("Talking Animation module not loaded");
return;
}
const apiUrl = getApiUrl();
const animationType = switchValue ? "start" : "stop";