Merge pull request #2872 from SillyTavern/super-saiyan-prompt-manager

Allow setting role, position and depth for marker prompts
This commit is contained in:
Cohee 2024-09-19 22:58:52 +03:00 committed by GitHub
commit 5269725f1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 58 additions and 7 deletions

View File

@ -316,3 +316,15 @@
margin-left: 0.5em;
}
}
.completion_prompt_manager_popup_entry_form_control:has(#completion_prompt_manager_popup_entry_form_prompt:disabled) > div:first-child::after {
content: 'The content of this prompt is pulled from elsewhere and cannot be edited here.';
display: block;
width: 100%;
font-weight: 600;
text-align: center;
}
.completion_prompt_manager_popup_entry_form_control #completion_prompt_manager_popup_entry_form_prompt:disabled {
visibility: hidden;
}

View File

@ -427,12 +427,13 @@ class PromptManager {
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_name').value = prompt.name;
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_role').value = 'system';
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.content ?? '';
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';
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').disabled = prompt.marker ?? false;
if (!this.systemPrompts.includes(promptId)) {
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').removeAttribute('disabled');
@ -920,7 +921,15 @@ class PromptManager {
* @returns {boolean} True if the prompt can be edited, false otherwise.
*/
isPromptEditAllowed(prompt) {
return !prompt.marker;
const forceEditPrompts = [
'charDescription',
'charPersonality',
'scenario',
'personaDescription',
'worldInfoBefore',
'worldInfoAfter',
];
return forceEditPrompts.includes(prompt.identifier) || !prompt.marker;
}
/**
@ -929,7 +938,17 @@ class PromptManager {
* @returns {boolean} True if the prompt can be deleted, false otherwise.
*/
isPromptToggleAllowed(prompt) {
const forceTogglePrompts = ['charDescription', 'charPersonality', 'scenario', 'personaDescription', 'worldInfoBefore', 'worldInfoAfter', 'main', 'chatHistory', 'dialogueExamples'];
const forceTogglePrompts = [
'charDescription',
'charPersonality',
'scenario',
'personaDescription',
'worldInfoBefore',
'worldInfoAfter',
'main',
'chatHistory',
'dialogueExamples',
];
return prompt.marker && !forceTogglePrompts.includes(prompt.identifier) ? false : !this.configuration.toggleDisabled.includes(prompt.identifier);
}
@ -1182,8 +1201,9 @@ class PromptManager {
const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block');
nameField.value = prompt.name ?? '';
roleField.value = prompt.role ?? '';
roleField.value = prompt.role ?? 'system';
promptField.value = prompt.content ?? '';
promptField.disabled = prompt.marker ?? false;
injectionPositionField.value = prompt.injection_position ?? INJECTION_POSITION.RELATIVE;
injectionDepthField.value = prompt.injection_depth ?? DEFAULT_DEPTH;
injectionDepthBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
@ -1279,6 +1299,7 @@ class PromptManager {
nameField.value = '';
roleField.selectedIndex = 0;
promptField.value = '';
promptField.disabled = false;
injectionPositionField.selectedIndex = 0;
injectionPositionField.removeAttribute('disabled');
injectionDepthField.value = DEFAULT_DEPTH;

View File

@ -970,6 +970,12 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
}
const prompt = prompts.get(source);
if (prompt.injection_position === INJECTION_POSITION.ABSOLUTE) {
promptManager.log(`Skipping prompt ${source} because it is an absolute prompt`);
return;
}
const index = target ? prompts.index(target) : prompts.index(source);
const collection = new MessageCollection(source);
collection.add(Message.fromPrompt(prompt));
@ -1014,8 +1020,8 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
acc.push(prompt.identifier);
return acc;
}, []);
const userAbsolutePrompts = prompts.collection
.filter((prompt) => false === prompt.system_prompt && prompt.injection_position === INJECTION_POSITION.ABSOLUTE)
const absolutePrompts = prompts.collection
.filter((prompt) => prompt.injection_position === INJECTION_POSITION.ABSOLUTE)
.reduce((acc, prompt) => {
acc.push(prompt);
return acc;
@ -1080,7 +1086,7 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
}
// Add in-chat injections
messages = populationInjectionPrompts(userAbsolutePrompts, messages);
messages = populationInjectionPrompts(absolutePrompts, messages);
// Decide whether dialogue examples should always be added
if (power_user.pin_examples) {
@ -1217,6 +1223,18 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
// Merge system prompts with prompt manager prompts
systemPrompts.forEach(prompt => {
const collectionPrompt = prompts.get(prompt.identifier);
// Apply system prompt role/depth overrides if they set in the prompt manager
if (collectionPrompt) {
// In-Chat / Relative
prompt.injection_position = collectionPrompt.injection_position ?? prompt.injection_position;
// Depth for In-Chat
prompt.injection_depth = collectionPrompt.injection_depth ?? prompt.injection_depth;
// Role (system, user, assistant)
prompt.role = collectionPrompt.role ?? prompt.role;
}
const newPrompt = promptManager.preparePrompt(prompt);
const markerIndex = prompts.index(prompt.identifier);