Add quick edit drawer and fields for main and jailbreak

This commit is contained in:
maver 2023-07-31 17:51:32 +02:00
parent bd3136e114
commit 1b7a1cbc4a
3 changed files with 57 additions and 4 deletions

View File

@ -1289,9 +1289,29 @@
<span data-i18n="May help the model to understand context. Names must only contain letters or numbers.">Helps the model to associate messages in group chats. Names must only contain letters or numbers without whitespaces.</span>
</div>
</div>
<div class="range-block m-t-1 m-b-1">
<div class="range-block m-b-1">
<div id="completion_prompt_manager"></div>
</div>
<div class="inline-drawer m-t-1 m-b-1 wide100p">
<div class="inline-drawer-toggle inline-drawer-header">
<b>Quick Edit</b>
<div class="fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>
</div>
<div class="inline-drawer-content">
<div class="range-block m-t-1">
<div class="justifyLeft" data-i18n="Main">Main</div>
<div class="wide100p">
<textarea id="main_prompt_quick_edit_textarea" class="text_pole textarea_compact" name="impersonation_prompt" rows="3" placeholder=""></textarea>
</div>
</div>
<div class="range-block m-t-1">
<div class="justifyLeft" data-i18n="Jailbreak">Jailbreak</div>
<div class="wide100p">
<textarea id="jailbreak_prompt_quick_edit_textarea" class="text_pole textarea_compact" rows="3" placeholder=""></textarea>
</div>
</div>
</div>
</div>
<div class="inline-drawer wide100p">
<div class="inline-drawer-toggle inline-drawer-header">
<b>Utility Prompts</b>

View File

@ -300,6 +300,38 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
this.saveServiceSettings().then(() => this.render());
};
// Factory function for creating quick edit elements
const saveSettings = this.saveServiceSettings;
const createQuickEdit = function() {
return {
element: null,
prompt: null,
from(element, prompt) {
this.element = element;
element.value = prompt.content ?? '';
element.addEventListener('input', () => {
prompt.content = element.value;
saveSettings();
});
return this;
},
update(value) {
this.element.value = value;
}
}
}
const mainPrompt = this.getPromptById('main');
const mainPromptTextarea = document.getElementById('main_prompt_quick_edit_textarea');
const mainQuickEdit = createQuickEdit().from(mainPromptTextarea, mainPrompt);
const jailbreakPrompt = this.getPromptById('jailbreak');
const jailbreakPromptTextarea = document.getElementById('jailbreak_prompt_quick_edit_textarea');
const jailbreakQuickEdit = createQuickEdit().from(jailbreakPromptTextarea, jailbreakPrompt);
// Save prompt edit form to settings and close form.
this.handleSavePrompt = (event) => {
const promptId = event.target.dataset.pmPrompt;
@ -313,6 +345,9 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
this.updatePromptWithPromptEditForm(prompt);
}
if ('main' === promptId) mainQuickEdit.update(prompt.content)
if ('jailbreak' === promptId) jailbreakQuickEdit.update(prompt.content)
this.log('Saved prompt: ' + promptId);
this.hidePopup();

View File

@ -1862,9 +1862,7 @@ function loadOpenAISettings(data, settings) {
$('#openai_external_category').toggle(oai_settings.show_external_models);
if (settings.impersonation_prompt !== undefined) oai_settings.impersonation_prompt = settings.impersonation_prompt;
$('#main_prompt_textarea').val(oai_settings.main_prompt);
$('#nsfw_prompt_textarea').val(oai_settings.nsfw_prompt);
$('#jailbreak_prompt_textarea').val(oai_settings.jailbreak_prompt);
$('#impersonation_prompt_textarea').val(oai_settings.impersonation_prompt);
$('#nsfw_avoidance_prompt_textarea').val(oai_settings.nsfw_avoidance_prompt);