Allow setting role, position and depth for marker prompts

This commit is contained in:
Cohee 2024-09-18 21:51:10 +03:00
parent 38d24f4b59
commit 82b0733d88
3 changed files with 59 additions and 7 deletions

View File

@ -316,3 +316,15 @@
margin-left: 0.5em; 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_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_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_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_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_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)) { 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');
@ -920,7 +921,16 @@ class PromptManager {
* @returns {boolean} True if the prompt can be edited, false otherwise. * @returns {boolean} True if the prompt can be edited, false otherwise.
*/ */
isPromptEditAllowed(prompt) { isPromptEditAllowed(prompt) {
return !prompt.marker; const forceEditPrompts = [
'charDescription',
'charPersonality',
'scenario',
'personaDescription',
'worldInfoBefore',
'worldInfoAfter',
'dialogueExamples',
];
return forceEditPrompts.includes(prompt.identifier) || !prompt.marker;
} }
/** /**
@ -929,7 +939,17 @@ class PromptManager {
* @returns {boolean} True if the prompt can be deleted, false otherwise. * @returns {boolean} True if the prompt can be deleted, false otherwise.
*/ */
isPromptToggleAllowed(prompt) { 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); return prompt.marker && !forceTogglePrompts.includes(prompt.identifier) ? false : !this.configuration.toggleDisabled.includes(prompt.identifier);
} }
@ -1182,8 +1202,9 @@ class PromptManager {
const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block'); 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 ?? 'system';
promptField.value = prompt.content ?? ''; promptField.value = prompt.content ?? '';
promptField.disabled = prompt.marker ?? false;
injectionPositionField.value = prompt.injection_position ?? INJECTION_POSITION.RELATIVE; injectionPositionField.value = prompt.injection_position ?? INJECTION_POSITION.RELATIVE;
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';
@ -1279,6 +1300,7 @@ class PromptManager {
nameField.value = ''; nameField.value = '';
roleField.selectedIndex = 0; roleField.selectedIndex = 0;
promptField.value = ''; promptField.value = '';
promptField.disabled = false;
injectionPositionField.selectedIndex = 0; injectionPositionField.selectedIndex = 0;
injectionPositionField.removeAttribute('disabled'); injectionPositionField.removeAttribute('disabled');
injectionDepthField.value = DEFAULT_DEPTH; injectionDepthField.value = DEFAULT_DEPTH;

View File

@ -970,6 +970,12 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
} }
const prompt = prompts.get(source); 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 index = target ? prompts.index(target) : prompts.index(source);
const collection = new MessageCollection(source); const collection = new MessageCollection(source);
collection.add(Message.fromPrompt(prompt)); collection.add(Message.fromPrompt(prompt));
@ -1014,8 +1020,8 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
acc.push(prompt.identifier); acc.push(prompt.identifier);
return acc; return acc;
}, []); }, []);
const userAbsolutePrompts = prompts.collection const absolutePrompts = prompts.collection
.filter((prompt) => false === prompt.system_prompt && prompt.injection_position === INJECTION_POSITION.ABSOLUTE) .filter((prompt) => prompt.injection_position === INJECTION_POSITION.ABSOLUTE)
.reduce((acc, prompt) => { .reduce((acc, prompt) => {
acc.push(prompt); acc.push(prompt);
return acc; return acc;
@ -1080,7 +1086,7 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
} }
// Add in-chat injections // Add in-chat injections
messages = populationInjectionPrompts(userAbsolutePrompts, messages); messages = populationInjectionPrompts(absolutePrompts, messages);
// Decide whether dialogue examples should always be added // Decide whether dialogue examples should always be added
if (power_user.pin_examples) { if (power_user.pin_examples) {
@ -1217,6 +1223,18 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
// Merge system prompts with prompt manager prompts // Merge system prompts with prompt manager prompts
systemPrompts.forEach(prompt => { 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 newPrompt = promptManager.preparePrompt(prompt);
const markerIndex = prompts.index(prompt.identifier); const markerIndex = prompts.index(prompt.identifier);