From 3b637cc9a6074f2c17e1cde5f32a29423fa2af8a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:28:35 +0200 Subject: [PATCH] Add forbid overrides to prompts --- public/css/promptmanager.css | 10 ++++++--- public/index.html | 18 +++++++++++---- public/scripts/PromptManager.js | 39 ++++++++++++++++++++++++++------- public/scripts/openai.js | 4 ++-- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/public/css/promptmanager.css b/public/css/promptmanager.css index 8cd6f7357..89e11dbff 100644 --- a/public/css/promptmanager.css +++ b/public/css/promptmanager.css @@ -19,13 +19,12 @@ #completion_prompt_manager #completion_prompt_manager_list li { display: grid; - grid-template-columns: 4fr 80px 60px; + grid-template-columns: 4fr 80px 40px; margin-bottom: 0.5em; width: 100% } #completion_prompt_manager #completion_prompt_manager_list .completion_prompt_manager_prompt .completion_prompt_manager_prompt_name .fa-solid { - padding: 0 0.5em; color: var(--white50a); } @@ -40,6 +39,7 @@ #completion_prompt_manager #completion_prompt_manager_list li.completion_prompt_manager_list_head .prompt_manager_prompt_tokens, #completion_prompt_manager #completion_prompt_manager_list li.completion_prompt_manager_prompt .prompt_manager_prompt_tokens { + font-size: calc(var(--mainFontSize)*0.9); text-align: right; } @@ -237,6 +237,10 @@ font-size: 12px; } +#completion_prompt_manager .completion_prompt_manager_important a { + font-weight: 600; +} + #completion_prompt_manager_footer_append_prompt { font-size: 16px; } @@ -305,4 +309,4 @@ #completion_prompt_manager #completion_prompt_manager_list li.completion_prompt_manager_prompt span span span { margin-left: 0.5em; } -} \ No newline at end of file +} diff --git a/public/index.html b/public/index.html index 165f41fef..f6adf96de 100644 --- a/public/index.html +++ b/public/index.html @@ -4962,10 +4962,20 @@
- -
The prompt to be sent.
+
+
+ +
The prompt to be sent.
+
+
+ +
+
diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index 875e2559c..30e128d46 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -70,7 +70,7 @@ const registerPromptManagerMigration = () => { * Represents a prompt. */ class Prompt { - identifier; role; content; name; system_prompt; position; injection_position; injection_depth; + identifier; role; content; name; system_prompt; position; injection_position; injection_depth; forbid_overrides; /** * Create a new Prompt instance. @@ -84,8 +84,9 @@ class Prompt { * @param {string} param0.position - The position of the prompt in the prompt list. * @param {number} param0.injection_position - The insert position of the prompt. * @param {number} param0.injection_depth - The depth of the prompt in the chat. + * @param {boolean} param0.forbid_overrides - Indicates if the prompt should not be overridden. */ - constructor({ identifier, role, content, name, system_prompt, position, injection_depth, injection_position } = {}) { + constructor({ identifier, role, content, name, system_prompt, position, injection_depth, injection_position, forbid_overrides } = {}) { this.identifier = identifier; this.role = role; this.content = content; @@ -94,6 +95,7 @@ class Prompt { this.position = position; this.injection_depth = injection_depth; this.injection_position = injection_position; + this.forbid_overrides = forbid_overrides; } } @@ -187,6 +189,11 @@ class PromptManager { 'enhanceDefinitions', ]; + this.overridablePrompts = [ + 'main', + 'jailbreak', + ]; + this.configuration = { version: 1, prefix: '', @@ -389,6 +396,7 @@ class PromptManager { case 'main': prompt.name = 'Main Prompt'; prompt.content = this.configuration.defaultPrompts.main; + prompt.forbid_overrides = false; break; case 'nsfw': prompt.name = 'Nsfw Prompt'; @@ -397,6 +405,7 @@ class PromptManager { case 'jailbreak': prompt.name = 'Jailbreak Prompt'; prompt.content = this.configuration.defaultPrompts.jailbreak; + prompt.forbid_overrides = false; break; case 'enhanceDefinitions': prompt.name = 'Enhance Definitions'; @@ -410,6 +419,8 @@ class PromptManager { document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').value = prompt.injection_position ?? 0; document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth').value = prompt.injection_depth ?? DEFAULT_DEPTH; document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block').style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden'; + document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides').checked = prompt.forbid_overrides ?? false; + document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block').style.visibility = this.overridablePrompts.includes(prompt.identifier) ? 'visible' : 'hidden'; if (!this.systemPrompts.includes(promptId)) { document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').removeAttribute('disabled'); @@ -711,6 +722,7 @@ class PromptManager { prompt.content = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').value; prompt.injection_position = Number(document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').value); prompt.injection_depth = Number(document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth').value); + prompt.forbid_overrides = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides').checked; } /** @@ -1133,6 +1145,8 @@ class PromptManager { const injectionPositionField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position'); const injectionDepthField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth'); const injectionDepthBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block'); + const forbidOverridesField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides'); + const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block'); nameField.value = prompt.name ?? ''; roleField.value = prompt.role ?? ''; @@ -1141,6 +1155,8 @@ class PromptManager { injectionDepthField.value = prompt.injection_depth ?? DEFAULT_DEPTH; injectionDepthBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden'; injectionPositionField.removeAttribute('disabled'); + forbidOverridesField.checked = prompt.forbid_overrides ?? false; + forbidOverridesBlock.style.visibility = this.overridablePrompts.includes(prompt.identifier) ? 'visible' : 'hidden'; if (this.systemPrompts.includes(prompt.identifier)) { injectionPositionField.setAttribute('disabled', 'disabled'); @@ -1224,6 +1240,8 @@ class PromptManager { const injectionPositionField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position'); const injectionDepthField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth'); const injectionDepthBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block'); + const forbidOverridesField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides'); + const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block'); nameField.value = ''; roleField.selectedIndex = 0; @@ -1232,6 +1250,8 @@ class PromptManager { injectionPositionField.removeAttribute('disabled'); injectionDepthField.value = DEFAULT_DEPTH; injectionDepthBlock.style.visibility = 'unset'; + forbidOverridesBlock.style.visibility = 'unset'; + forbidOverridesField.checked = false; roleField.disabled = false; } @@ -1501,16 +1521,19 @@ class PromptManager { } const encodedName = escapeHtml(prompt.name); - const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE; + const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && !prompt.forbid_overrides; + const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides; const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE; const isInjectionPrompt = !prompt.marker && prompt.injection_position === INJECTION_POSITION.ABSOLUTE; + const importantClass = isImportantPrompt ? `${prefix}prompt_manager_important` : ''; listItemHtml += ` -
  • +
  • - ${prompt.marker ? '' : ''} - ${isSystemPrompt ? '' : ''} - ${isUserPrompt ? '' : ''} - ${isInjectionPrompt ? '' : ''} + ${prompt.marker ? '' : ''} + ${isSystemPrompt ? '' : ''} + ${isImportantPrompt ? '' : ''} + ${isUserPrompt ? '' : ''} + ${isInjectionPrompt ? '' : ''} ${this.isPromptInspectionAllowed(prompt) ? `${encodedName}` : encodedName} ${isInjectionPrompt ? `@ ${prompt.injection_depth}` : ''} diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 77a0f4954..e265276c3 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -1091,7 +1091,7 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor // Apply character-specific main prompt const systemPrompt = prompts.get('main') ?? null; - if (systemPromptOverride && systemPrompt) { + if (systemPromptOverride && systemPrompt && systemPrompt.forbid_overrides !== true) { const mainOriginalContent = systemPrompt.content; systemPrompt.content = systemPromptOverride; const mainReplacement = promptManager.preparePrompt(systemPrompt, mainOriginalContent); @@ -1100,7 +1100,7 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor // Apply character-specific jailbreak const jailbreakPrompt = prompts.get('jailbreak') ?? null; - if (jailbreakPromptOverride && jailbreakPrompt) { + if (jailbreakPromptOverride && jailbreakPrompt && jailbreakPrompt.forbid_overrides !== true) { const jbOriginalContent = jailbreakPrompt.content; jailbreakPrompt.content = jailbreakPromptOverride; const jbReplacement = promptManager.preparePrompt(jailbreakPrompt, jbOriginalContent);