Show calculated prompts for makers

This commit is contained in:
maver 2023-06-01 18:53:02 +02:00
parent 24acba557c
commit e47d9d979b

View File

@ -281,9 +281,13 @@ PromptManagerModule.prototype.sanitizeServiceSettings = function () {
}; };
PromptManagerModule.prototype.recalculateTokens = function () { PromptManagerModule.prototype.recalculateTokens = function () {
(this.serviceSettings.prompts ?? []).forEach(prompt => prompt.calculated_tokens = this.getTokenCountForPrompt(prompt)); (this.serviceSettings.prompts ?? []).forEach(prompt => prompt.calculated_tokens = (true === prompt.marker ? prompt.calculated_tokens : this.getTokenCountForPrompt(prompt)));
}; };
PromptManagerModule.prototype.recalculateTotalActiveTokens = function () {
this.totalActiveTokens = this.getPromptsForCharacter(this.activeCharacter, true).reduce((sum, prompt) => sum + Number(prompt.calculated_tokens), 0);
}
PromptManagerModule.prototype.getTokenCountForPrompt = function (prompt) { PromptManagerModule.prototype.getTokenCountForPrompt = function (prompt) {
if (!prompt.role || !prompt.content) return 0; if (!prompt.role || !prompt.content) return 0;
return countTokens({ return countTokens({
@ -296,10 +300,6 @@ PromptManagerModule.prototype.isPromptDeletionAllowed = function (prompt) {
return false === prompt.system_prompt; return false === prompt.system_prompt;
} }
PromptManagerModule.prototype.recalculateTotalActiveTokens = function () {
this.totalActiveTokens = this.getPromptsForCharacter(this.activeCharacter, true).reduce((sum, prompt) => sum + Number(prompt.calculated_tokens), 0);
}
PromptManagerModule.prototype.handleCharacterSelected = function (event) { PromptManagerModule.prototype.handleCharacterSelected = function (event) {
this.activeCharacter = {id: event.detail.id, ...event.detail.character}; this.activeCharacter = {id: event.detail.id, ...event.detail.character};
@ -315,7 +315,7 @@ PromptManagerModule.prototype.getPromptsForCharacter = function (character, only
.filter(prompt => null !== prompt); .filter(prompt => null !== prompt);
} }
// Get the prompt order for a given character, otherwise an empty array is returned. // Get the prompt order for a given character, otherwise an empty array is returned.
PromptManagerModule.prototype.getPromptListByCharacter = function (character) { PromptManagerModule.prototype.getPromptListByCharacter = function (character) {
return character === null ? [] : (this.serviceSettings.prompt_lists.find(list => String(list.character_id) === String(character.id))?.list ?? []); return character === null ? [] : (this.serviceSettings.prompt_lists.find(list => String(list.character_id) === String(character.id))?.list ?? []);
} }
@ -514,16 +514,13 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
const nameSpan = document.createElement('span'); const nameSpan = document.createElement('span');
nameSpan.textContent = 'Name'; nameSpan.textContent = 'Name';
const roleSpan = document.createElement('span');
roleSpan.textContent = 'Role';
const tokensSpan = document.createElement('span'); const tokensSpan = document.createElement('span');
tokensSpan.classList.add('prompt_manager_prompt_tokens');
tokensSpan.textContent = 'Tokens'; tokensSpan.textContent = 'Tokens';
promptManagerListHead.appendChild(nameSpan); promptManagerListHead.appendChild(nameSpan);
promptManagerListHead.appendChild(roleSpan);
promptManagerListHead.appendChild(tokensSpan);
promptManagerListHead.appendChild(document.createElement('span')); promptManagerListHead.appendChild(document.createElement('span'));
promptManagerListHead.appendChild(tokensSpan);
promptManagerList.appendChild(promptManagerListHead); promptManagerList.appendChild(promptManagerListHead);
@ -543,22 +540,14 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
if (prompt.identifier !== 'newMainChat' && if (prompt.identifier !== 'newMainChat' &&
prompt.identifier !== 'chatHistory' && prompt.identifier !== 'chatHistory' &&
false === advancedEnabled) return; false === advancedEnabled) return;
const listItem = document.createElement('li');
listItem.classList.add(this.configuration.prefix + 'prompt_manager_prompt', this.configuration.prefix + 'prompt_manager_marker');
listItem.classList.add('dropAllowed');
if (true === draggableEnabled) listItem.classList.add('draggable');
listItem.setAttribute('draggable', String(draggableEnabled));
listItem.setAttribute('data-pm-identifier', prompt.identifier);
listItem.textContent = prompt.name;
promptManagerList.appendChild(listItem);
return;
} }
const listItem = document.createElement('li'); const listItem = document.createElement('li');
listItem.classList.add(this.configuration.prefix + 'prompt_manager_prompt'); listItem.classList.add(this.configuration.prefix + 'prompt_manager_prompt');
if (true === draggableEnabled) listItem.classList.add('draggable'); if (true === draggableEnabled) listItem.classList.add('draggable');
if (prompt.marker) listItem.classList.add(this.configuration.prefix + 'prompt_manager_marker');
const listEntry = this.getPromptListEntry(this.activeCharacter, prompt.identifier); const listEntry = this.getPromptListEntry(this.activeCharacter, prompt.identifier);
if (false === listEntry.enabled) listItem.classList.add(this.configuration.prefix + 'prompt_manager_prompt_disabled'); if (false === listEntry.enabled) listItem.classList.add(this.configuration.prefix + 'prompt_manager_prompt_disabled');
listItem.classList.add('dropAllowed'); listItem.classList.add('dropAllowed');
@ -569,15 +558,14 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
nameSpan.setAttribute('data-pm-name', prompt.name); nameSpan.setAttribute('data-pm-name', prompt.name);
nameSpan.textContent = prompt.name; nameSpan.textContent = prompt.name;
const roleSpan = document.createElement('span');
roleSpan.setAttribute('data-pm-role', prompt.role);
roleSpan.textContent = prompt.role;
const tokensSpan = document.createElement('span'); const tokensSpan = document.createElement('span');
tokensSpan.classList.add('prompt_manager_prompt_tokens')
tokensSpan.setAttribute('data-pm-tokens', prompt.calculated_tokens); tokensSpan.setAttribute('data-pm-tokens', prompt.calculated_tokens);
tokensSpan.textContent = prompt.calculated_tokens; tokensSpan.textContent = prompt.calculated_tokens ? prompt.calculated_tokens : '-';
const actionsSpan = document.createElement('span'); const actionsSpan = document.createElement('span');
actionsSpan.classList.add('prompt_manager_prompt_controls');
// Don't add delete control to system prompts // Don't add delete control to system prompts
if (true === this.isPromptDeletionAllowed(prompt)) { if (true === this.isPromptDeletionAllowed(prompt)) {
@ -607,9 +595,9 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
controlSpan.append(actionsSpan) controlSpan.append(actionsSpan)
listItem.appendChild(nameSpan); listItem.appendChild(nameSpan);
listItem.appendChild(roleSpan); if (prompt.marker) listItem.appendChild(document.createElement('span'));
else listItem.appendChild(controlSpan);
listItem.appendChild(tokensSpan); listItem.appendChild(tokensSpan);
listItem.appendChild(controlSpan);
promptManagerList.appendChild(listItem); promptManagerList.appendChild(listItem);
}); });
@ -794,4 +782,4 @@ const defaultPromptManagerSettings = {
} }
}; };
export {PromptManagerModule, openAiDefaultPrompts, openAiDefaultPromptLists, defaultPromptManagerSettings}; export {PromptManagerModule, openAiDefaultPrompts, openAiDefaultPromptLists, defaultPromptManagerSettings};