From 1b7a1cbc4a51b4bb5147f016ed07f17fece0799d Mon Sep 17 00:00:00 2001 From: maver Date: Mon, 31 Jul 2023 17:51:32 +0200 Subject: [PATCH] Add quick edit drawer and fields for main and jailbreak --- public/index.html | 22 ++++++++++++++++++++- public/scripts/PromptManager.js | 35 +++++++++++++++++++++++++++++++++ public/scripts/openai.js | 4 +--- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 33563a6c9..8c79ddfe3 100644 --- a/public/index.html +++ b/public/index.html @@ -1289,9 +1289,29 @@ Helps the model to associate messages in group chats. Names must only contain letters or numbers without whitespaces. -
+
+
+
+ Quick Edit +
+
+
+
+
Main
+
+ +
+
+
+
Jailbreak
+
+ +
+
+
+
Utility Prompts diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index f7087be30..ecd9076a6 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -300,6 +300,38 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti this.saveServiceSettings().then(() => this.render()); }; + // Factory function for creating quick edit elements + const saveSettings = this.saveServiceSettings; + const createQuickEdit = function() { + return { + element: null, + prompt: null, + + from(element, prompt) { + this.element = element; + element.value = prompt.content ?? ''; + element.addEventListener('input', () => { + prompt.content = element.value; + saveSettings(); + }); + + return this; + }, + + update(value) { + this.element.value = value; + } + } + } + + const mainPrompt = this.getPromptById('main'); + const mainPromptTextarea = document.getElementById('main_prompt_quick_edit_textarea'); + const mainQuickEdit = createQuickEdit().from(mainPromptTextarea, mainPrompt); + + const jailbreakPrompt = this.getPromptById('jailbreak'); + const jailbreakPromptTextarea = document.getElementById('jailbreak_prompt_quick_edit_textarea'); + const jailbreakQuickEdit = createQuickEdit().from(jailbreakPromptTextarea, jailbreakPrompt); + // Save prompt edit form to settings and close form. this.handleSavePrompt = (event) => { const promptId = event.target.dataset.pmPrompt; @@ -313,6 +345,9 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti this.updatePromptWithPromptEditForm(prompt); } + if ('main' === promptId) mainQuickEdit.update(prompt.content) + if ('jailbreak' === promptId) jailbreakQuickEdit.update(prompt.content) + this.log('Saved prompt: ' + promptId); this.hidePopup(); diff --git a/public/scripts/openai.js b/public/scripts/openai.js index e13820862..7dd95c55d 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -1862,9 +1862,7 @@ function loadOpenAISettings(data, settings) { $('#openai_external_category').toggle(oai_settings.show_external_models); if (settings.impersonation_prompt !== undefined) oai_settings.impersonation_prompt = settings.impersonation_prompt; - $('#main_prompt_textarea').val(oai_settings.main_prompt); - $('#nsfw_prompt_textarea').val(oai_settings.nsfw_prompt); - $('#jailbreak_prompt_textarea').val(oai_settings.jailbreak_prompt); + $('#impersonation_prompt_textarea').val(oai_settings.impersonation_prompt); $('#nsfw_avoidance_prompt_textarea').val(oai_settings.nsfw_avoidance_prompt);