Disable toggling of main prompt

This commit is contained in:
maver
2023-06-21 19:42:12 +02:00
parent 85862d8b2e
commit be30fef700
2 changed files with 42 additions and 7 deletions

View File

@ -64,6 +64,7 @@ function PromptManagerModule() {
containerIdentifier: '',
listIdentifier: '',
listItemTemplateIdentifier: '',
toggleDisabled: [],
draggable: true
};
@ -367,6 +368,24 @@ PromptManagerModule.prototype.isPromptDeletionAllowed = function (prompt) {
return false === prompt.system_prompt;
}
/**
* Check whether a prompt can be edited.
* @param {object} prompt - The prompt to check.
* @returns {boolean} True if the prompt can be deleted, false otherwise.
*/
PromptManagerModule.prototype.isPromptEditAllowed = function (prompt) {
return true;
}
/**
* Check whether a prompt can be toggled on or off.
* @param {object} prompt - The prompt to check.
* @returns {boolean} True if the prompt can be deleted, false otherwise.
*/
PromptManagerModule.prototype.isPromptToggleAllowed = function (prompt) {
return !this.configuration.toggleDisabled.includes(prompt.identifier);
}
/**
* Handle the deletion of a character by removing their prompt list and nullifying the active character if it was the one deleted.
* @param {object} event - The event object containing the character's ID.
@ -706,7 +725,21 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
let detachSpanHtml = '';
if (this.isPromptDeletionAllowed(prompt)) {
detachSpanHtml = `
<span title="delete" class="caution fa-solid fa-x"></span>
<span title="delete" class="prompt-manager-detach-action caution fa-solid fa-x"></span>
`;
}
let editSpanHtml = '';
if (this.isPromptEditAllowed(prompt)) {
editSpanHtml = `
<span title="edit" class="prompt-manager-edit-action fa-solid fa-pencil"></span>
`;
}
let toggleSpanHtml = '';
if (this.isPromptToggleAllowed(prompt)) {
toggleSpanHtml = `
<span class="prompt-manager-toggle-action ${listEntry.enabled ? 'fa-solid fa-toggle-on' : 'fa-solid fa-toggle-off'}"></span>
`;
}
@ -720,8 +753,8 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
<span>
<span class="prompt_manager_prompt_controls">
${detachSpanHtml}
<span title="edit" class="fa-solid fa-pencil"></span>
<span class="${listEntry.enabled ? 'fa-solid fa-toggle-on' : 'fa-solid fa-toggle-off'}"></span>
${editSpanHtml}
${toggleSpanHtml}
</span>
</span>
`}
@ -733,15 +766,15 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
promptManagerList.insertAdjacentHTML('beforeend', listItemHtml);
// Now that the new elements are in the DOM, you can add the event listeners.
Array.from(promptManagerList.getElementsByClassName('fa-x')).forEach(el => {
Array.from(promptManagerList.getElementsByClassName('prompt-manager-detach-action')).forEach(el => {
el.addEventListener('click', this.handleDetach);
});
Array.from(promptManagerList.getElementsByClassName('fa-pencil')).forEach(el => {
Array.from(promptManagerList.getElementsByClassName('prompt-manager-edit-action')).forEach(el => {
el.addEventListener('click', this.handleEdit);
});
Array.from(promptManagerList.querySelectorAll('.prompt_manager_prompt_controls span:last-child')).forEach(el => {
Array.from(promptManagerList.querySelectorAll('.prompt-manager-toggle-action')).forEach(el => {
el.addEventListener('click', this.handleToggle);
});
};

View File

@ -277,6 +277,7 @@ function setupOpenAIPromptManager(openAiSettings) {
prefix: 'openai_',
containerIdentifier: 'openai_prompt_manager',
listIdentifier: 'openai_prompt_manager_list',
toggleDisabled: ['main'],
draggable: true
};
@ -580,11 +581,12 @@ async function prepareOpenAIMessages({
try {
populateChatCompletion(prompts, chatCompletion, {bias, quietPrompt, type});
} catch (error) {
toastr.error('An error occurred while counting tokens.')
if (error instanceof TokenBudgetExceededError) {
toastr.error('An error occurred while counting tokens: Token budget exceeded.')
chatCompletion.log('Token budget exceeded.');
promptManager.error = 'Not enough free tokens for mandatory prompts. Raise your token Limit or disable custom prompts.';
} else {
toastr.error('An unknown error occurred while counting tokens. Further info available in console.')
chatCompletion.log('Unexpected error:');
chatCompletion.log(error);
}