From cbfc1f7a0e801c4931ea97e3c1c78b46cb86e2bf Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Wed, 26 Mar 2025 01:50:26 +0100 Subject: [PATCH] Add 'none' classifier API option and set as default Introduces a no-op API selection to disable expression classification Shows warnings when no valid API is selected to prevent silent failures Updates migration logic and settings UI to use new default value This allows users to explicitly opt-out of automatic expression detection while maintaining backwards compatibility with existing configurations --- .../scripts/extensions/expressions/index.js | 21 ++++++++++++++++--- .../extensions/expressions/settings.html | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index c36c7f5e3..3d9395774 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -83,6 +83,7 @@ const EXPRESSION_API = { extras: 1, llm: 2, webllm: 3, + none: 99, }; let expressionsList = null; @@ -692,6 +693,11 @@ async function classifyCallback(/** @type {{api: string?, filter: string?, promp const expressionApi = EXPRESSION_API[api] || extension_settings.expressions.api; const filterAvailable = !isFalseBoolean(filter); + if (expressionApi === EXPRESSION_API.none) { + toastr.warning('No classifier API selected'); + return ''; + } + if (!modules.includes('classify') && expressionApi == EXPRESSION_API.extras) { toastr.warning('Text classification is disabled or not available'); return ''; @@ -1061,7 +1067,7 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin return parseLlmResponse(emotionResponse, expressionsList); } // Extras - default: { + case EXPRESSION_API.extras: { const url = new URL(getApiUrl()); url.pathname = '/api/classify'; @@ -1079,6 +1085,15 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin return data.classification[0].label; } } break; + // None + case EXPRESSION_API.none: { + // Return empty, the fallback expression will be used + return ''; + } + default: { + toastr.error('Invalid API selected'); + return ''; + } } } catch (error) { toastr.error('Could not classify expression. Check the console or your backend for more information.'); @@ -2060,7 +2075,7 @@ async function fetchImagesNoCache() { function migrateSettings() { if (extension_settings.expressions.api === undefined) { - extension_settings.expressions.api = EXPRESSION_API.local; + extension_settings.expressions.api = EXPRESSION_API.none; saveSettingsDebounced(); } @@ -2142,7 +2157,7 @@ function migrateSettings() { $('#open_chat_expressions').hide(); await renderAdditionalExpressionSettings(); - $('#expression_api').val(extension_settings.expressions.api ?? EXPRESSION_API.extras); + $('#expression_api').val(extension_settings.expressions.api ?? EXPRESSION_API.none); $('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api)); $('#expression_llm_prompt').val(extension_settings.expressions.llmPrompt ?? ''); $('#expression_llm_prompt').on('input', function () { diff --git a/public/scripts/extensions/expressions/settings.html b/public/scripts/extensions/expressions/settings.html index 98938cf4d..36d725ba2 100644 --- a/public/scripts/extensions/expressions/settings.html +++ b/public/scripts/extensions/expressions/settings.html @@ -22,6 +22,7 @@ Select the API for classifying expressions.