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