From d65a03d75d8cf86f004e5795aee4a98e89fdf235 Mon Sep 17 00:00:00 2001 From: maver Date: Sat, 10 Jun 2023 18:13:59 +0200 Subject: [PATCH] Streamline token counting By using TokenHandler instead of custom token handling --- public/scripts/PromptManager.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index d3497e144..a28736526 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -491,7 +491,7 @@ PromptManagerModule.prototype.getPromptListEntry = function (character, identifi * @returns {Object|null} The prompt object, or null if not found */ PromptManagerModule.prototype.getPromptById = function (identifier) { - return this.serviceSettings.prompts.find(item => item.identifier === identifier) ?? null; + return this.serviceSettings.prompts.find(item => item && item.identifier === identifier) ?? null; } /** @@ -576,6 +576,7 @@ PromptManagerModule.prototype.renderPromptManager = function () { const showAdvancedSettings = this.serviceSettings.prompt_manager_settings.showAdvancedSettings; const checkSpanClass = showAdvancedSettings ? 'fa-solid fa-toggle-on' : 'fa-solid fa-toggle-off'; + const totalActiveTokens = this.tokenHandler?.getTotal(); promptManagerDiv.insertAdjacentHTML('beforeend', `
@@ -590,7 +591,7 @@ PromptManagerModule.prototype.renderPromptManager = function () { Show advanced options
-
Total Tokens: ${this.totalActiveTokens}
+
Total Tokens: ${totalActiveTokens}
@@ -603,7 +604,7 @@ PromptManagerModule.prototype.renderPromptManager = function () { if (null !== this.activeCharacter) { const prompts = [...this.serviceSettings.prompts] - .filter(prompt => !prompt.system_prompt) + .filter(prompt => !prompt?.system_prompt) .sort((promptA, promptB) => promptA.name.localeCompare(promptB.name)) .reduce((acc, prompt) => acc + ``, ''); @@ -663,7 +664,7 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () { const enabledClass = listEntry.enabled ? '' : `${prefix}prompt_manager_prompt_disabled`; const draggableClass = draggableEnabled ? 'draggable' : prompt.marker ? 'droppable' : ''; const markerClass = prompt.marker ? `${prefix}prompt_manager_marker` : ''; - const calculatedTokens = this.tokenHandler?.getCounts()[prompt.identifier]; + const calculatedTokens = this.tokenHandler?.getCounts()[prompt.identifier] ?? ''; let detachSpanHtml = ''; if (this.isPromptDeletionAllowed(prompt)) {