Add forbid overrides to prompts

This commit is contained in:
Cohee 2024-03-24 01:28:35 +02:00
parent c1ac34e001
commit 3b637cc9a6
4 changed files with 54 additions and 17 deletions

View File

@ -19,13 +19,12 @@
#completion_prompt_manager #completion_prompt_manager_list li { #completion_prompt_manager #completion_prompt_manager_list li {
display: grid; display: grid;
grid-template-columns: 4fr 80px 60px; grid-template-columns: 4fr 80px 40px;
margin-bottom: 0.5em; margin-bottom: 0.5em;
width: 100% width: 100%
} }
#completion_prompt_manager #completion_prompt_manager_list .completion_prompt_manager_prompt .completion_prompt_manager_prompt_name .fa-solid { #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); 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_list_head .prompt_manager_prompt_tokens,
#completion_prompt_manager #completion_prompt_manager_list li.completion_prompt_manager_prompt .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; text-align: right;
} }
@ -237,6 +237,10 @@
font-size: 12px; font-size: 12px;
} }
#completion_prompt_manager .completion_prompt_manager_important a {
font-weight: 600;
}
#completion_prompt_manager_footer_append_prompt { #completion_prompt_manager_footer_append_prompt {
font-size: 16px; font-size: 16px;
} }
@ -305,4 +309,4 @@
#completion_prompt_manager #completion_prompt_manager_list li.completion_prompt_manager_prompt span span span { #completion_prompt_manager #completion_prompt_manager_list li.completion_prompt_manager_prompt span span span {
margin-left: 0.5em; margin-left: 0.5em;
} }
} }

View File

@ -4962,10 +4962,20 @@
</div> </div>
</div> </div>
<div class="completion_prompt_manager_popup_entry_form_control"> <div class="completion_prompt_manager_popup_entry_form_control">
<label for="completion_prompt_manager_popup_entry_form_prompt"> <div class="flex-container alignItemsCenter">
<span>Prompt</span> <div class="flex1">
</label> <label for="completion_prompt_manager_popup_entry_form_prompt">
<div class="text_muted">The prompt to be sent.</div> <span>Prompt</span>
</label>
<div class="text_muted">The prompt to be sent.</div>
</div>
<div id="completion_prompt_manager_forbid_overrides_block">
<label class="checkbox_label" for="completion_prompt_manager_popup_entry_form_forbid_overrides" title="This prompt cannot be overridden by character cards, even if overrides are preferred.">
<input type="checkbox" id="completion_prompt_manager_popup_entry_form_forbid_overrides" name="forbid_overrides" />
<span>Forbid Overrides</span>
</label>
</div>
</div>
<textarea id="completion_prompt_manager_popup_entry_form_prompt" class="text_pole" name="prompt"> <textarea id="completion_prompt_manager_popup_entry_form_prompt" class="text_pole" name="prompt">
</textarea> </textarea>
</div> </div>

View File

@ -70,7 +70,7 @@ const registerPromptManagerMigration = () => {
* Represents a prompt. * Represents a prompt.
*/ */
class 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. * 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 {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_position - The insert position of the prompt.
* @param {number} param0.injection_depth - The depth of the prompt in the chat. * @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.identifier = identifier;
this.role = role; this.role = role;
this.content = content; this.content = content;
@ -94,6 +95,7 @@ class Prompt {
this.position = position; this.position = position;
this.injection_depth = injection_depth; this.injection_depth = injection_depth;
this.injection_position = injection_position; this.injection_position = injection_position;
this.forbid_overrides = forbid_overrides;
} }
} }
@ -187,6 +189,11 @@ class PromptManager {
'enhanceDefinitions', 'enhanceDefinitions',
]; ];
this.overridablePrompts = [
'main',
'jailbreak',
];
this.configuration = { this.configuration = {
version: 1, version: 1,
prefix: '', prefix: '',
@ -389,6 +396,7 @@ class PromptManager {
case 'main': case 'main':
prompt.name = 'Main Prompt'; prompt.name = 'Main Prompt';
prompt.content = this.configuration.defaultPrompts.main; prompt.content = this.configuration.defaultPrompts.main;
prompt.forbid_overrides = false;
break; break;
case 'nsfw': case 'nsfw':
prompt.name = 'Nsfw Prompt'; prompt.name = 'Nsfw Prompt';
@ -397,6 +405,7 @@ class PromptManager {
case 'jailbreak': case 'jailbreak':
prompt.name = 'Jailbreak Prompt'; prompt.name = 'Jailbreak Prompt';
prompt.content = this.configuration.defaultPrompts.jailbreak; prompt.content = this.configuration.defaultPrompts.jailbreak;
prompt.forbid_overrides = false;
break; break;
case 'enhanceDefinitions': case 'enhanceDefinitions':
prompt.name = 'Enhance Definitions'; 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_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_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_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)) { if (!this.systemPrompts.includes(promptId)) {
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').removeAttribute('disabled'); 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.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_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.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 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 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 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 ?? ''; nameField.value = prompt.name ?? '';
roleField.value = prompt.role ?? ''; roleField.value = prompt.role ?? '';
@ -1141,6 +1155,8 @@ class PromptManager {
injectionDepthField.value = prompt.injection_depth ?? DEFAULT_DEPTH; injectionDepthField.value = prompt.injection_depth ?? DEFAULT_DEPTH;
injectionDepthBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden'; injectionDepthBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
injectionPositionField.removeAttribute('disabled'); 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)) { if (this.systemPrompts.includes(prompt.identifier)) {
injectionPositionField.setAttribute('disabled', 'disabled'); 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 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 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 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 = ''; nameField.value = '';
roleField.selectedIndex = 0; roleField.selectedIndex = 0;
@ -1232,6 +1250,8 @@ class PromptManager {
injectionPositionField.removeAttribute('disabled'); injectionPositionField.removeAttribute('disabled');
injectionDepthField.value = DEFAULT_DEPTH; injectionDepthField.value = DEFAULT_DEPTH;
injectionDepthBlock.style.visibility = 'unset'; injectionDepthBlock.style.visibility = 'unset';
forbidOverridesBlock.style.visibility = 'unset';
forbidOverridesField.checked = false;
roleField.disabled = false; roleField.disabled = false;
} }
@ -1501,16 +1521,19 @@ class PromptManager {
} }
const encodedName = escapeHtml(prompt.name); 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 isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
const isInjectionPrompt = !prompt.marker && prompt.injection_position === INJECTION_POSITION.ABSOLUTE; const isInjectionPrompt = !prompt.marker && prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
const importantClass = isImportantPrompt ? `${prefix}prompt_manager_important` : '';
listItemHtml += ` listItemHtml += `
<li class="${prefix}prompt_manager_prompt ${draggableClass} ${enabledClass} ${markerClass}" data-pm-identifier="${prompt.identifier}"> <li class="${prefix}prompt_manager_prompt ${draggableClass} ${enabledClass} ${markerClass} ${importantClass}" data-pm-identifier="${prompt.identifier}">
<span class="${prefix}prompt_manager_prompt_name" data-pm-name="${encodedName}"> <span class="${prefix}prompt_manager_prompt_name" data-pm-name="${encodedName}">
${prompt.marker ? '<span class="fa-solid fa-thumb-tack" title="Marker"></span>' : ''} ${prompt.marker ? '<span class="fa-fw fa-solid fa-thumb-tack" title="Marker"></span>' : ''}
${isSystemPrompt ? '<span class="fa-solid fa-square-poll-horizontal" title="Global Prompt"></span>' : ''} ${isSystemPrompt ? '<span class="fa-fw fa-solid fa-square-poll-horizontal" title="Global Prompt"></span>' : ''}
${isUserPrompt ? '<span class="fa-solid fa-user" title="User Prompt"></span>' : ''} ${isImportantPrompt ? '<span class="fa-fw fa-solid fa-star" title="Important Prompt"></span>' : ''}
${isInjectionPrompt ? '<span class="fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''} ${isUserPrompt ? '<span class="fa-fw fa-solid fa-user" title="User Prompt"></span>' : ''}
${isInjectionPrompt ? '<span class="fa-fw fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''}
${this.isPromptInspectionAllowed(prompt) ? `<a class="prompt-manager-inspect-action">${encodedName}</a>` : encodedName} ${this.isPromptInspectionAllowed(prompt) ? `<a class="prompt-manager-inspect-action">${encodedName}</a>` : encodedName}
${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${prompt.injection_depth}</small>` : ''} ${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${prompt.injection_depth}</small>` : ''}
</span> </span>

View File

@ -1091,7 +1091,7 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
// Apply character-specific main prompt // Apply character-specific main prompt
const systemPrompt = prompts.get('main') ?? null; const systemPrompt = prompts.get('main') ?? null;
if (systemPromptOverride && systemPrompt) { if (systemPromptOverride && systemPrompt && systemPrompt.forbid_overrides !== true) {
const mainOriginalContent = systemPrompt.content; const mainOriginalContent = systemPrompt.content;
systemPrompt.content = systemPromptOverride; systemPrompt.content = systemPromptOverride;
const mainReplacement = promptManager.preparePrompt(systemPrompt, mainOriginalContent); const mainReplacement = promptManager.preparePrompt(systemPrompt, mainOriginalContent);
@ -1100,7 +1100,7 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
// Apply character-specific jailbreak // Apply character-specific jailbreak
const jailbreakPrompt = prompts.get('jailbreak') ?? null; const jailbreakPrompt = prompts.get('jailbreak') ?? null;
if (jailbreakPromptOverride && jailbreakPrompt) { if (jailbreakPromptOverride && jailbreakPrompt && jailbreakPrompt.forbid_overrides !== true) {
const jbOriginalContent = jailbreakPrompt.content; const jbOriginalContent = jailbreakPrompt.content;
jailbreakPrompt.content = jailbreakPromptOverride; jailbreakPrompt.content = jailbreakPromptOverride;
const jbReplacement = promptManager.preparePrompt(jailbreakPrompt, jbOriginalContent); const jbReplacement = promptManager.preparePrompt(jailbreakPrompt, jbOriginalContent);