Shut tokenization errors if not using ooba Closes #2849

93bf87b035a730912db67ff6cb4cde325bea6a58

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +9 -3Ignore whitespace
public/script.js+4 -1
@@ -211,7 +211,7 @@ import {
211211 selectContextPreset,
212212} from './scripts/instruct-mode.js';
213213import { initLocales, t, translate } from './scripts/i18n.js';
214214import { getFriendlyTokenizerName, getTokenCount, getTokenCountAsync, getTokenizerModel, initTokenizers, saveTokenCache, TOKENIZER_SUPPORTED_KEY } from './scripts/tokenizers.js';
215215import {
216216 user_avatar,
217217 getUserAvatars,
@@ -1216,6 +1216,9 @@ async function getStatusTextgen() {
12161216 // Determine instruct mode preset
12171217 autoSelectInstructPreset(online_status);
12181218
1219+ const supportsTokenization = response.headers.get('x-supports-tokenization') === 'true';
1220+ supportsTokenization ? sessionStorage.setItem(TOKENIZER_SUPPORTED_KEY, 'true') : sessionStorage.removeItem(TOKENIZER_SUPPORTED_KEY);
1221+
12191222 // We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress.
12201223 if (online_status === 'no_connection' && data.response) {
12211224 toastr.error(data.response, 'API Error', { timeOut: 5000, preventDuplicates: true });
public/scripts/tokenizers.js+4 -2
@@ -10,7 +10,8 @@ import { getCurrentDreamGenModelTokenizer, getCurrentOpenRouterModelTokenizer, o
1010const { OOBA, TABBY, KOBOLDCPP, VLLM, APHRODITE, LLAMACPP, OPENROUTER, DREAMGEN } = textgen_types;
1111
1212export const CHARACTERS_PER_TOKEN_RATIO = 3.35;
1313export const TOKENIZER_WARNING_KEY = 'tokenizationWarningShown';
14+export const TOKENIZER_SUPPORTED_KEY = 'tokenizationSupported';
1415
1516export const tokenizers = {
1617 NONE: 0,
@@ -280,8 +281,9 @@ export function getTokenizerBestMatch(forApi) {
280281 // - Kobold must pass a version check
281282 // - Tokenizer haven't reported an error previously
282283 const hasTokenizerError = sessionStorage.getItem(TOKENIZER_WARNING_KEY);
284+ const hasValidEndpoint = sessionStorage.getItem(TOKENIZER_SUPPORTED_KEY);
283285 const isConnected = online_status !== 'no_connection';
284286 const isTokenizerSupported = TEXTGEN_TOKENIZERS.includes(textgen_settings.type) && (textgen_settings.type !== OOBA || hasValidEndpoint);
285287
286288 if (!hasTokenizerError && isConnected) {
287289 if (forApi === 'kobold' && kai_flags.can_use_tokenization) {
src/endpoints/backends/text-completions.js+1 -0
@@ -186,6 +186,7 @@ router.post('/status', jsonParser, async function (request, response) {
186186
187187 const modelName = modelInfo?.model_name;
188188 result = modelName || result;
189+ response.setHeader('x-supports-tokenization', 'true');
189190 }
190191 } catch (error) {
191192 console.error(`Failed to get Ooba model info: ${error}`);