From c0bc425c8b676839b15aa44745a43425bfd5c9e4 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 13 Aug 2023 18:43:17 +0300 Subject: [PATCH] Debounce manager changes --- public/index.html | 27 -------------------------- public/script.js | 4 ++-- public/scripts/PromptManager.js | 18 ++++++++++------- public/scripts/extensions/tts/index.js | 7 ++++++- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/public/index.html b/public/index.html index 7eaba4710..4940ae4c6 100644 --- a/public/index.html +++ b/public/index.html @@ -3743,33 +3743,6 @@ -
-
-
- -
- -
- Chat History - ? -
- -
-
- -
- -
-
-
-
-
-
diff --git a/public/script.js b/public/script.js index d0412806a..c6ba4fbcf 100644 --- a/public/script.js +++ b/public/script.js @@ -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 () { diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index 134347b9c..c34a56e71 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -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') }; diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index d1a4d8bef..344642895 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -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";