Merge pull request #2872 from SillyTavern/super-saiyan-prompt-manager Allow setting role, position and depth for marker prompts

5269725f1c4fb51f18384b21e6bf7d03426660c3

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
3 files changed, +58 -7Showing whitespace changes
public/css/promptmanager.css+12 -0
@@ -316,3 +316,15 @@
316316 margin-left: 0.5em;
317317 }
318318}
319+
320+.completion_prompt_manager_popup_entry_form_control:has(#completion_prompt_manager_popup_entry_form_prompt:disabled) > div:first-child::after {
321+ content: 'The content of this prompt is pulled from elsewhere and cannot be edited here.';
322+ display: block;
323+ width: 100%;
324+ font-weight: 600;
325+ text-align: center;
326+}
327+
328+.completion_prompt_manager_popup_entry_form_control #completion_prompt_manager_popup_entry_form_prompt:disabled {
329+ visibility: hidden;
330+}
public/scripts/PromptManager.js+25 -4
@@ -427,12 +427,13 @@ class PromptManager {
427427
428428 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_name').value = prompt.name;
429429 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_role').value = 'system';
430430 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').value = prompt.content ?? '';
431431 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').value = prompt.injection_position ?? 0;
432432 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth').value = prompt.injection_depth ?? DEFAULT_DEPTH;
433433 document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block').style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
434434 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides').checked = prompt.forbid_overrides ?? false;
435435 document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block').style.visibility = this.overridablePrompts.includes(prompt.identifier) ? 'visible' : 'hidden';
436+ document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').disabled = prompt.marker ?? false;
436437
437438 if (!this.systemPrompts.includes(promptId)) {
438439 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').removeAttribute('disabled');
@@ -920,7 +921,15 @@ class PromptManager {
920921 * @returns {boolean} True if the prompt can be edited, false otherwise.
921922 */
922923 isPromptEditAllowed(prompt) {
923- return !prompt.marker;
924+ const forceEditPrompts = [
925+ 'charDescription',
926+ 'charPersonality',
927+ 'scenario',
928+ 'personaDescription',
929+ 'worldInfoBefore',
930+ 'worldInfoAfter',
931+ ];
932+ return forceEditPrompts.includes(prompt.identifier) || !prompt.marker;
924933 }
925934
926935 /**
@@ -929,7 +938,17 @@ class PromptManager {
929938 * @returns {boolean} True if the prompt can be deleted, false otherwise.
930939 */
931940 isPromptToggleAllowed(prompt) {
932- const forceTogglePrompts = ['charDescription', 'charPersonality', 'scenario', 'personaDescription', 'worldInfoBefore', 'worldInfoAfter', 'main', 'chatHistory', 'dialogueExamples'];
941+ const forceTogglePrompts = [
942+ 'charDescription',
943+ 'charPersonality',
944+ 'scenario',
945+ 'personaDescription',
946+ 'worldInfoBefore',
947+ 'worldInfoAfter',
948+ 'main',
949+ 'chatHistory',
950+ 'dialogueExamples',
951+ ];
933952 return prompt.marker && !forceTogglePrompts.includes(prompt.identifier) ? false : !this.configuration.toggleDisabled.includes(prompt.identifier);
934953 }
935954
@@ -1182,8 +1201,9 @@ class PromptManager {
11821201 const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block');
11831202
11841203 nameField.value = prompt.name ?? '';
11851204 roleField.value = prompt.role ?? 'system';
11861205 promptField.value = prompt.content ?? '';
1206+ promptField.disabled = prompt.marker ?? false;
11871207 injectionPositionField.value = prompt.injection_position ?? INJECTION_POSITION.RELATIVE;
11881208 injectionDepthField.value = prompt.injection_depth ?? DEFAULT_DEPTH;
11891209 injectionDepthBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
@@ -1279,6 +1299,7 @@ class PromptManager {
12791299 nameField.value = '';
12801300 roleField.selectedIndex = 0;
12811301 promptField.value = '';
1302+ promptField.disabled = false;
12821303 injectionPositionField.selectedIndex = 0;
12831304 injectionPositionField.removeAttribute('disabled');
12841305 injectionDepthField.value = DEFAULT_DEPTH;
public/scripts/openai.js+21 -3
@@ -970,6 +970,12 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
970970 }
971971
972972 const prompt = prompts.get(source);
973+
974+ if (prompt.injection_position === INJECTION_POSITION.ABSOLUTE) {
975+ promptManager.log(`Skipping prompt ${source} because it is an absolute prompt`);
976+ return;
977+ }
978+
973979 const index = target ? prompts.index(target) : prompts.index(source);
974980 const collection = new MessageCollection(source);
975981 collection.add(Message.fromPrompt(prompt));
@@ -1014,8 +1020,8 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
10141020 acc.push(prompt.identifier);
10151021 return acc;
10161022 }, []);
10171023 const userAbsolutePromptsabsolutePrompts = prompts.collection
10181024 .filter((prompt) => false === prompt.system_prompt && prompt.injection_position === INJECTION_POSITION.ABSOLUTE)
10191025 .reduce((acc, prompt) => {
10201026 acc.push(prompt);
10211027 return acc;
@@ -1080,7 +1086,7 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
10801086 }
10811087
10821088 // Add in-chat injections
10831089 messages = populationInjectionPrompts(userAbsolutePromptsabsolutePrompts, messages);
10841090
10851091 // Decide whether dialogue examples should always be added
10861092 if (power_user.pin_examples) {
@@ -1217,6 +1223,18 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
12171223
12181224 // Merge system prompts with prompt manager prompts
12191225 systemPrompts.forEach(prompt => {
1226+ const collectionPrompt = prompts.get(prompt.identifier);
1227+
1228+ // Apply system prompt role/depth overrides if they set in the prompt manager
1229+ if (collectionPrompt) {
1230+ // In-Chat / Relative
1231+ prompt.injection_position = collectionPrompt.injection_position ?? prompt.injection_position;
1232+ // Depth for In-Chat
1233+ prompt.injection_depth = collectionPrompt.injection_depth ?? prompt.injection_depth;
1234+ // Role (system, user, assistant)
1235+ prompt.role = collectionPrompt.role ?? prompt.role;
1236+ }
1237+
12201238 const newPrompt = promptManager.preparePrompt(prompt);
12211239 const markerIndex = prompts.index(prompt.identifier);
12221240