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 | extras: 1, | 83 | extras: 1, |
| 84 | llm: 2, | 84 | llm: 2, |
| 85 | webllm: 3, | 85 | webllm: 3, |
| 86 | none: 99, | ||
| 86 | }; | 87 | }; |
| 87 | 88 | ||
| 88 | let expressionsList = null; | 89 | let expressionsList = null; |
| @@ -692,6 +693,11 @@ async function classifyCallback(/** @type {{api: string?, filter: string?, promp | |||
| 692 | const expressionApi = EXPRESSION_API[api] || extension_settings.expressions.api; | 693 | const expressionApi = EXPRESSION_API[api] || extension_settings.expressions.api; |
| 693 | const filterAvailable = !isFalseBoolean(filter); | 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 | if (!modules.includes('classify') && expressionApi == EXPRESSION_API.extras) { | 701 | if (!modules.includes('classify') && expressionApi == EXPRESSION_API.extras) { |
| 696 | toastr.warning('Text classification is disabled or not available'); | 702 | toastr.warning('Text classification is disabled or not available'); |
| 697 | return ''; | 703 | return ''; |
| @@ -1061,7 +1067,7 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin | |||
| 1061 | return parseLlmResponse(emotionResponse, expressionsList); | 1067 | return parseLlmResponse(emotionResponse, expressionsList); |
| 1062 | } | 1068 | } |
| 1063 | // Extras | 1069 | // Extras |
| 1064 | default: { | 1070 | case EXPRESSION_API.extras: { |
| 1065 | const url = new URL(getApiUrl()); | 1071 | const url = new URL(getApiUrl()); |
| 1066 | url.pathname = '/api/classify'; | 1072 | url.pathname = '/api/classify'; |
| 1067 | 1073 | ||
| @@ -1079,6 +1085,15 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin | |||
| 1079 | return data.classification[0].label; | 1085 | return data.classification[0].label; |
| 1080 | } | 1086 | } |
| 1081 | } break; | 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 | } catch (error) { | 1098 | } catch (error) { |
| 1084 | toastr.error('Could not classify expression. Check the console or your backend for more information.'); | 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 | function migrateSettings() { | 2076 | function migrateSettings() { |
| 2062 | if (extension_settings.expressions.api === undefined) { | 2077 | if (extension_settings.expressions.api === undefined) { |
| 2063 | extension_settings.expressions.api = EXPRESSION_API.local; | 2078 | extension_settings.expressions.api = EXPRESSION_API.none; |
| 2064 | saveSettingsDebounced(); | 2079 | saveSettingsDebounced(); |
| 2065 | } | 2080 | } |
| 2066 | 2081 | ||
| @@ -2142,7 +2157,7 @@ function migrateSettings() { | |||
| 2142 | $('#open_chat_expressions').hide(); | 2157 | $('#open_chat_expressions').hide(); |
| 2143 | 2158 | ||
| 2144 | await renderAdditionalExpressionSettings(); | 2159 | await renderAdditionalExpressionSettings(); |
| 2145 | $('#expression_api').val(extension_settings.expressions.api ?? EXPRESSION_API.extras); | 2160 | $('#expression_api').val(extension_settings.expressions.api ?? EXPRESSION_API.none); |
| 2146 | $('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api)); | 2161 | $('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api)); |
| 2147 | $('#expression_llm_prompt').val(extension_settings.expressions.llmPrompt ?? ''); | 2162 | $('#expression_llm_prompt').val(extension_settings.expressions.llmPrompt ?? ''); |
| 2148 | $('#expression_llm_prompt').on('input', function () { | 2163 | $('#expression_llm_prompt').on('input', function () { |
| @@ -22,6 +22,7 @@ | |||
| 22 | <label for="expression_api" data-i18n="Classifier API">Classifier API</label> | 22 | <label for="expression_api" data-i18n="Classifier API">Classifier API</label> |
| 23 | <small data-i18n="Select the API for classifying expressions.">Select the API for classifying expressions.</small> | 23 | <small data-i18n="Select the API for classifying expressions.">Select the API for classifying expressions.</small> |
| 24 | <select id="expression_api" class="flex1 margin0"> | 24 | <select id="expression_api" class="flex1 margin0"> |
| 25 | <option value="99" data-i18n="[ None ]">[ None ]</option> | ||
| 25 | <option value="0" data-i18n="Local">Local</option> | 26 | <option value="0" data-i18n="Local">Local</option> |
| 26 | <option value="1" data-i18n="Extras">Extras (deprecated)</option> | 27 | <option value="1" data-i18n="Extras">Extras (deprecated)</option> |
| 27 | <option value="2" data-i18n="Main API">Main API</option> | 28 | <option value="2" data-i18n="Main API">Main API</option> |