From 9543f54f8c359834a9173f33fa4116efe32e8145 Mon Sep 17 00:00:00 2001 From: maver Date: Mon, 14 Aug 2023 18:15:19 +0200 Subject: [PATCH 1/6] Fix user jb/main not replacing original placeholder in character main/jb --- public/scripts/openai.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index e4e8ad1d5..50e421586 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -726,33 +726,23 @@ function preparePromptsForChatCompletion(Scenario, charPersonality, name2, world // Apply character-specific main prompt const systemPromptOverride = promptManager.activeCharacter.data?.system_prompt ?? null; const systemPrompt = prompts.get('main') ?? null; - if (systemPromptOverride) { + if (systemPromptOverride && systemPrompt) { + const mainOriginalContent = systemPrompt.content; systemPrompt.content = systemPromptOverride; - prompts.set(systemPrompt, prompts.index('main')); + const mainReplacement = promptManager.preparePrompt(systemPrompt, mainOriginalContent); + prompts.set(mainReplacement, prompts.index('main')); } // Apply character-specific jailbreak const jailbreakPromptOverride = promptManager.activeCharacter.data?.post_history_instructions ?? null; const jailbreakPrompt = prompts.get('jailbreak') ?? null; if (jailbreakPromptOverride && jailbreakPrompt) { + const jbOriginalContent = jailbreakPrompt.content; jailbreakPrompt.content = jailbreakPromptOverride; - prompts.set(jailbreakPrompt, prompts.index('jailbreak')); + const jbReplacement = promptManager.preparePrompt(jailbreakPrompt, jbOriginalContent); + prompts.set(jbReplacement, prompts.index('jailbreak')); } - // Replace {{original}} placeholder for supported prompts - const originalReplacements = { - main: default_main_prompt, - nsfw: default_nsfw_prompt, - jailbreak: default_jailbreak_prompt - } - - prompts.collection.forEach(prompt => { - if (originalReplacements.hasOwnProperty(prompt.identifier)) { - const original = originalReplacements[prompt.identifier]; - prompt.content = promptManager.preparePrompt(prompt, original)?.content; - } - }); - // Allow subscribers to manipulate the prompts object eventSource.emit(event_types.OAI_BEFORE_CHATCOMPLETION, prompts); From 6caa8a47659943146caf391d997a4633af1e746e Mon Sep 17 00:00:00 2001 From: maver Date: Mon, 14 Aug 2023 18:21:43 +0200 Subject: [PATCH 2/6] Add nsfw prompt to quick edit drawer --- public/index.html | 13 ++++++++++--- public/scripts/PromptManager.js | 9 +++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index 0a2c37e73..341ba4131 100644 --- a/public/index.html +++ b/public/index.html @@ -166,7 +166,8 @@

Chat Completion Presets

- @@ -1352,13 +1353,19 @@
Main
- + +
+
+
+
Main
+
+
Jailbreak
- +
diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index ddf889637..e352bdf61 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -330,6 +330,10 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti const mainPromptTextarea = document.getElementById('main_prompt_quick_edit_textarea'); const mainQuickEdit = createQuickEdit().from(mainPromptTextarea, mainPrompt); + const nsfwPrompt = this.getPromptById('nsfw'); + const nsfwPromptTextarea = document.getElementById('nsfw_prompt_quick_edit_textarea'); + const nsfwQuickEdit = createQuickEdit().from(nsfwPromptTextarea, nsfwPrompt); + const jailbreakPrompt = this.getPromptById('jailbreak'); const jailbreakPromptTextarea = document.getElementById('jailbreak_prompt_quick_edit_textarea'); const jailbreakQuickEdit = createQuickEdit().from(jailbreakPromptTextarea, jailbreakPrompt); @@ -347,8 +351,9 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti this.updatePromptWithPromptEditForm(prompt); } - if ('main' === promptId) mainQuickEdit.update(prompt.content) - if ('jailbreak' === promptId) jailbreakQuickEdit.update(prompt.content) + if ('main' === promptId) mainQuickEdit.update(prompt.content); + if ('nsfw' === promptId) nsfwQuickEdit.update(prompt.content); + if ('jailbreak' === promptId) jailbreakQuickEdit.update(prompt.content); this.log('Saved prompt: ' + promptId); From 033dc45ab99b4e2182e2316ab7eab618f06cc5f8 Mon Sep 17 00:00:00 2001 From: maver Date: Mon, 14 Aug 2023 18:28:03 +0200 Subject: [PATCH 3/6] Move quick edit ui identifiers into configuration --- public/index.html | 2 +- public/scripts/PromptManager.js | 11 ++++++++--- public/scripts/openai.js | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 341ba4131..c7bf3d727 100644 --- a/public/index.html +++ b/public/index.html @@ -1357,7 +1357,7 @@
-
Main
+
NSFW
diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index e352bdf61..93a2d4766 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -159,6 +159,11 @@ function PromptManagerModule() { jailbreak: '', enhanceDefinitions: '' }, + quickEdit: { + main: '', + nsfw: '', + jailbreak: '' + } }; // Chatcompletion configuration object @@ -327,15 +332,15 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti } const mainPrompt = this.getPromptById('main'); - const mainPromptTextarea = document.getElementById('main_prompt_quick_edit_textarea'); + const mainPromptTextarea = document.getElementById(this.configuration.quickEdit.main); const mainQuickEdit = createQuickEdit().from(mainPromptTextarea, mainPrompt); const nsfwPrompt = this.getPromptById('nsfw'); - const nsfwPromptTextarea = document.getElementById('nsfw_prompt_quick_edit_textarea'); + const nsfwPromptTextarea = document.getElementById(this.configuration.quickEdit.nsfw); const nsfwQuickEdit = createQuickEdit().from(nsfwPromptTextarea, nsfwPrompt); const jailbreakPrompt = this.getPromptById('jailbreak'); - const jailbreakPromptTextarea = document.getElementById('jailbreak_prompt_quick_edit_textarea'); + const jailbreakPromptTextarea = document.getElementById(this.configuration.quickEdit.jailbreak); const jailbreakQuickEdit = createQuickEdit().from(jailbreakPromptTextarea, jailbreakPrompt); // Save prompt edit form to settings and close form. diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 50e421586..fbb979105 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -348,6 +348,11 @@ function setupChatCompletionPromptManager(openAiSettings) { jailbreak: default_jailbreak_prompt, enhanceDefinitions: default_enhance_definitions_prompt }, + quickEdit: { + main: 'main_prompt_quick_edit_textarea', + nsfw: 'nsfw_prompt_quick_edit_textarea', + jailbreak: 'jailbreak_prompt_quick_edit_textarea' + } }; promptManager.saveServiceSettings = () => { From dbf38d359d728a10f63ff1aae37d67ea0b361049 Mon Sep 17 00:00:00 2001 From: maver Date: Mon, 14 Aug 2023 20:21:07 +0200 Subject: [PATCH 4/6] Debounce quick edit saving --- public/scripts/PromptManager.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index 93a2d4766..735a2172e 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -1,4 +1,4 @@ -import {callPopup, event_types, eventSource, main_api, substituteParams} from "../script.js"; +import {callPopup, event_types, eventSource, main_api, saveSettingsDebounced, substituteParams} from "../script.js"; import {TokenHandler} from "./openai.js"; import {power_user} from "./power-user.js"; import { debounce } from "./utils.js"; @@ -308,7 +308,6 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti }; // Factory function for creating quick edit elements - const saveSettings = this.saveServiceSettings; const createQuickEdit = function() { return { element: null, @@ -319,7 +318,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti element.value = prompt.content ?? ''; element.addEventListener('input', () => { prompt.content = element.value; - saveSettings(); + saveSettingsDebounced() }); return this; From 1e71c631ae5af89dfe01adf7eeee570e7aba28f6 Mon Sep 17 00:00:00 2001 From: maver Date: Mon, 14 Aug 2023 20:27:16 +0200 Subject: [PATCH 5/6] Always show prompt manager edit popup on top --- public/css/promptmanager.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/css/promptmanager.css b/public/css/promptmanager.css index 737a1f1c3..a964e9fd6 100644 --- a/public/css/promptmanager.css +++ b/public/css/promptmanager.css @@ -263,7 +263,7 @@ padding: 1em; border: 1px solid #333333; flex-direction: column; - z-index: 3010; + z-index: 3010 !important; border-radius: 0 0 20px 20px; background-color: var(--SmartThemeBlurTintColor); } From 151a13eefa0983aa33aea08c0cc77bbf50c98d13 Mon Sep 17 00:00:00 2001 From: maver Date: Mon, 14 Aug 2023 20:35:45 +0200 Subject: [PATCH 6/6] Fix formatting --- public/index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index c7bf3d727..89f0667ff 100644 --- a/public/index.html +++ b/public/index.html @@ -166,8 +166,7 @@

Chat Completion Presets

-