mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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
This commit is contained in:
@ -83,6 +83,7 @@ const EXPRESSION_API = {
|
|||||||
extras: 1,
|
extras: 1,
|
||||||
llm: 2,
|
llm: 2,
|
||||||
webllm: 3,
|
webllm: 3,
|
||||||
|
none: 99,
|
||||||
};
|
};
|
||||||
|
|
||||||
let expressionsList = null;
|
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 expressionApi = EXPRESSION_API[api] || extension_settings.expressions.api;
|
||||||
const filterAvailable = !isFalseBoolean(filter);
|
const filterAvailable = !isFalseBoolean(filter);
|
||||||
|
|
||||||
|
if (expressionApi === EXPRESSION_API.none) {
|
||||||
|
toastr.warning('No classifier API selected');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (!modules.includes('classify') && expressionApi == EXPRESSION_API.extras) {
|
if (!modules.includes('classify') && expressionApi == EXPRESSION_API.extras) {
|
||||||
toastr.warning('Text classification is disabled or not available');
|
toastr.warning('Text classification is disabled or not available');
|
||||||
return '';
|
return '';
|
||||||
@ -1061,7 +1067,7 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
|
|||||||
return parseLlmResponse(emotionResponse, expressionsList);
|
return parseLlmResponse(emotionResponse, expressionsList);
|
||||||
}
|
}
|
||||||
// Extras
|
// Extras
|
||||||
default: {
|
case EXPRESSION_API.extras: {
|
||||||
const url = new URL(getApiUrl());
|
const url = new URL(getApiUrl());
|
||||||
url.pathname = '/api/classify';
|
url.pathname = '/api/classify';
|
||||||
|
|
||||||
@ -1079,6 +1085,15 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
|
|||||||
return data.classification[0].label;
|
return data.classification[0].label;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
// None
|
||||||
|
case EXPRESSION_API.none: {
|
||||||
|
// Return empty, the fallback expression will be used
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
toastr.error('Invalid API selected');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toastr.error('Could not classify expression. Check the console or your backend for more information.');
|
toastr.error('Could not classify expression. Check the console or your backend for more information.');
|
||||||
@ -2060,7 +2075,7 @@ async function fetchImagesNoCache() {
|
|||||||
|
|
||||||
function migrateSettings() {
|
function migrateSettings() {
|
||||||
if (extension_settings.expressions.api === undefined) {
|
if (extension_settings.expressions.api === undefined) {
|
||||||
extension_settings.expressions.api = EXPRESSION_API.local;
|
extension_settings.expressions.api = EXPRESSION_API.none;
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2142,7 +2157,7 @@ function migrateSettings() {
|
|||||||
$('#open_chat_expressions').hide();
|
$('#open_chat_expressions').hide();
|
||||||
|
|
||||||
await renderAdditionalExpressionSettings();
|
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_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api));
|
||||||
$('#expression_llm_prompt').val(extension_settings.expressions.llmPrompt ?? '');
|
$('#expression_llm_prompt').val(extension_settings.expressions.llmPrompt ?? '');
|
||||||
$('#expression_llm_prompt').on('input', function () {
|
$('#expression_llm_prompt').on('input', function () {
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<label for="expression_api" data-i18n="Classifier API">Classifier API</label>
|
<label for="expression_api" data-i18n="Classifier API">Classifier API</label>
|
||||||
<small data-i18n="Select the API for classifying expressions.">Select the API for classifying expressions.</small>
|
<small data-i18n="Select the API for classifying expressions.">Select the API for classifying expressions.</small>
|
||||||
<select id="expression_api" class="flex1 margin0">
|
<select id="expression_api" class="flex1 margin0">
|
||||||
|
<option value="99" data-i18n="[ None ]">[ None ]</option>
|
||||||
<option value="0" data-i18n="Local">Local</option>
|
<option value="0" data-i18n="Local">Local</option>
|
||||||
<option value="1" data-i18n="Extras">Extras (deprecated)</option>
|
<option value="1" data-i18n="Extras">Extras (deprecated)</option>
|
||||||
<option value="2" data-i18n="Main API">Main API</option>
|
<option value="2" data-i18n="Main API">Main API</option>
|
||||||
|
Reference in New Issue
Block a user