Merge pull request #2872 from SillyTavern/super-saiyan-prompt-manager Allow setting role, position and depth for marker prompts
Signed| @@ -316,3 +316,15 @@ | ||
| 316 | 316 | margin-left: 0.5em; |
| 317 | 317 | } |
| 318 | 318 | } |
| 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 | +} | |
| @@ -427,12 +427,13 @@ class PromptManager { | ||
| 427 | 427 | |
| 428 | 428 | document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_name').value = prompt.name; |
| 429 | 429 | document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_role').value = 'system'; |
| 430 | 430 | document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').value = prompt.content ?? ''; |
| 431 | 431 | document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').value = prompt.injection_position ?? 0; |
| 432 | 432 | document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth').value = prompt.injection_depth ?? DEFAULT_DEPTH; |
| 433 | 433 | document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block').style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden'; |
| 434 | 434 | document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides').checked = prompt.forbid_overrides ?? false; |
| 435 | 435 | 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; | |
| 436 | 437 | |
| 437 | 438 | if (!this.systemPrompts.includes(promptId)) { |
| 438 | 439 | document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').removeAttribute('disabled'); |
| @@ -920,7 +921,15 @@ class PromptManager { | ||
| 920 | 921 | * @returns {boolean} True if the prompt can be edited, false otherwise. |
| 921 | 922 | */ |
| 922 | 923 | 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; | |
| 924 | 933 | } |
| 925 | 934 | |
| 926 | 935 | /** |
| @@ -929,7 +938,17 @@ class PromptManager { | ||
| 929 | 938 | * @returns {boolean} True if the prompt can be deleted, false otherwise. |
| 930 | 939 | */ |
| 931 | 940 | 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 | + ]; | |
| 933 | 952 | return prompt.marker && !forceTogglePrompts.includes(prompt.identifier) ? false : !this.configuration.toggleDisabled.includes(prompt.identifier); |
| 934 | 953 | } |
| 935 | 954 | |
| @@ -1182,8 +1201,9 @@ class PromptManager { | ||
| 1182 | 1201 | const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block'); |
| 1183 | 1202 | |
| 1184 | 1203 | nameField.value = prompt.name ?? ''; |
| 1185 | 1204 | roleField.value = prompt.role ?? 'system'; |
| 1186 | 1205 | promptField.value = prompt.content ?? ''; |
| 1206 | + promptField.disabled = prompt.marker ?? false; | |
| 1187 | 1207 | injectionPositionField.value = prompt.injection_position ?? INJECTION_POSITION.RELATIVE; |
| 1188 | 1208 | injectionDepthField.value = prompt.injection_depth ?? DEFAULT_DEPTH; |
| 1189 | 1209 | injectionDepthBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden'; |
| @@ -1279,6 +1299,7 @@ class PromptManager { | ||
| 1279 | 1299 | nameField.value = ''; |
| 1280 | 1300 | roleField.selectedIndex = 0; |
| 1281 | 1301 | promptField.value = ''; |
| 1302 | + promptField.disabled = false; | |
| 1282 | 1303 | injectionPositionField.selectedIndex = 0; |
| 1283 | 1304 | injectionPositionField.removeAttribute('disabled'); |
| 1284 | 1305 | injectionDepthField.value = DEFAULT_DEPTH; |
| @@ -970,6 +970,12 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm | ||
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | 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 | + | |
| 973 | 979 | const index = target ? prompts.index(target) : prompts.index(source); |
| 974 | 980 | const collection = new MessageCollection(source); |
| 975 | 981 | collection.add(Message.fromPrompt(prompt)); |
| @@ -1014,8 +1020,8 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm | ||
| 1014 | 1020 | acc.push(prompt.identifier); |
| 1015 | 1021 | return acc; |
| 1016 | 1022 | }, []); |
| 1017 | 1023 | const userAbsolutePromptsabsolutePrompts = prompts.collection |
| 1018 | 1024 | .filter((prompt) => false === prompt.system_prompt && prompt.injection_position === INJECTION_POSITION.ABSOLUTE) |
| 1019 | 1025 | .reduce((acc, prompt) => { |
| 1020 | 1026 | acc.push(prompt); |
| 1021 | 1027 | return acc; |
| @@ -1080,7 +1086,7 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm | ||
| 1080 | 1086 | } |
| 1081 | 1087 | |
| 1082 | 1088 | // Add in-chat injections |
| 1083 | 1089 | messages = populationInjectionPrompts(userAbsolutePromptsabsolutePrompts, messages); |
| 1084 | 1090 | |
| 1085 | 1091 | // Decide whether dialogue examples should always be added |
| 1086 | 1092 | if (power_user.pin_examples) { |
| @@ -1217,6 +1223,18 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor | ||
| 1217 | 1223 | |
| 1218 | 1224 | // Merge system prompts with prompt manager prompts |
| 1219 | 1225 | 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 | + | |
| 1220 | 1238 | const newPrompt = promptManager.preparePrompt(prompt); |
| 1221 | 1239 | const markerIndex = prompts.index(prompt.identifier); |
| 1222 | 1240 | |