Merge pull request #3760 from SillyTavern/feat/expressions-none-default-option Add 'none' expression classifier API option and set as default
Signed| @@ -83,6 +83,7 @@ const EXPRESSION_API = { | ||
| 83 | 83 | extras: 1, |
| 84 | 84 | llm: 2, |
| 85 | 85 | webllm: 3, |
| 86 | + none: 99, | |
| 86 | 87 | }; |
| 87 | 88 | |
| 88 | 89 | let expressionsList = null; |
| @@ -692,6 +693,11 @@ async function classifyCallback(/** @type {{api: string?, filter: string?, promp | ||
| 692 | 693 | const expressionApi = EXPRESSION_API[api] || extension_settings.expressions.api; |
| 693 | 694 | const filterAvailable = !isFalseBoolean(filter); |
| 694 | 695 | |
| 696 | + if (expressionApi === EXPRESSION_API.none) { | |
| 697 | + toastr.warning('No classifier API selected'); | |
| 698 | + return ''; | |
| 699 | + } | |
| 700 | + | |
| 695 | 701 | if (!modules.includes('classify') && expressionApi == EXPRESSION_API.extras) { |
| 696 | 702 | toastr.warning('Text classification is disabled or not available'); |
| 697 | 703 | return ''; |
| @@ -1061,7 +1067,7 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin | ||
| 1061 | 1067 | return parseLlmResponse(emotionResponse, expressionsList); |
| 1062 | 1068 | } |
| 1063 | 1069 | // Extras |
| 1064 | 1070 | defaultcase EXPRESSION_API.extras: { |
| 1065 | 1071 | const url = new URL(getApiUrl()); |
| 1066 | 1072 | url.pathname = '/api/classify'; |
| 1067 | 1073 | |
| @@ -1079,6 +1085,15 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin | ||
| 1079 | 1085 | return data.classification[0].label; |
| 1080 | 1086 | } |
| 1081 | 1087 | } break; |
| 1088 | + // None | |
| 1089 | + case EXPRESSION_API.none: { | |
| 1090 | + // Return empty, the fallback expression will be used | |
| 1091 | + return ''; | |
| 1092 | + } | |
| 1093 | + default: { | |
| 1094 | + toastr.error('Invalid API selected'); | |
| 1095 | + return ''; | |
| 1096 | + } | |
| 1082 | 1097 | } |
| 1083 | 1098 | } catch (error) { |
| 1084 | 1099 | toastr.error('Could not classify expression. Check the console or your backend for more information.'); |
| @@ -2060,7 +2075,7 @@ async function fetchImagesNoCache() { | ||
| 2060 | 2075 | |
| 2061 | 2076 | function migrateSettings() { |
| 2062 | 2077 | if (extension_settings.expressions.api === undefined) { |
| 2063 | 2078 | extension_settings.expressions.api = EXPRESSION_API.localnone; |
| 2064 | 2079 | saveSettingsDebounced(); |
| 2065 | 2080 | } |
| 2066 | 2081 | |
| @@ -2142,7 +2157,7 @@ function migrateSettings() { | ||
| 2142 | 2157 | $('#open_chat_expressions').hide(); |
| 2143 | 2158 | |
| 2144 | 2159 | await renderAdditionalExpressionSettings(); |
| 2145 | 2160 | $('#expression_api').val(extension_settings.expressions.api ?? EXPRESSION_API.extrasnone); |
| 2146 | 2161 | $('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api)); |
| 2147 | 2162 | $('#expression_llm_prompt').val(extension_settings.expressions.llmPrompt ?? ''); |
| 2148 | 2163 | $('#expression_llm_prompt').on('input', function () { |
| @@ -22,6 +22,7 @@ | ||
| 22 | 22 | <label for="expression_api" data-i18n="Classifier API">Classifier API</label> |
| 23 | 23 | <small data-i18n="Select the API for classifying expressions.">Select the API for classifying expressions.</small> |
| 24 | 24 | <select id="expression_api" class="flex1 margin0"> |
| 25 | + <option value="99" data-i18n="[ None ]">[ None ]</option> | |
| 25 | 26 | <option value="0" data-i18n="Local">Local</option> |
| 26 | 27 | <option value="1" data-i18n="Extras">Extras (deprecated)</option> |
| 27 | 28 | <option value="2" data-i18n="Main API">Main API</option> |