Retry API tokenization on reconnecting to backend

Fixes #5004
This commit is contained in:
Cohee
2026-01-14 02:16:56 +02:00
parent cd3bed87c1
commit 7e410b4aa8
+7 -1
View File
@@ -1,5 +1,5 @@
import { localforage } from '../lib.js';
import { characters, main_api, nai_settings, online_status, this_chid } from '../script.js';
import { characters, event_types, eventSource, main_api, nai_settings, online_status, this_chid } from '../script.js';
import { power_user, registerDebugFunction } from './power-user.js';
import { chat_completion_sources, model_list, oai_settings } from './openai.js';
import { groups, selected_group } from './group-chats.js';
@@ -1223,6 +1223,12 @@ export async function initTokenizers() {
textgen_types.VLLM,
textgen_types.APHRODITE,
);
eventSource.on(event_types.ONLINE_STATUS_CHANGED, async () => {
// Clear tokenizer warning when (re)connecting to an LLM backend that supports tokenization
if (main_api === 'textgenerationwebui' && TEXTGEN_TOKENIZERS.includes(textgen_settings.type)) {
sessionStorage.removeItem(TOKENIZER_WARNING_KEY);
}
});
await loadTokenCache();
registerDebugFunction('resetTokenCache', 'Reset token cache', 'Purges the calculated token counts. Use this if you want to force a full re-tokenization of all chats or suspect the token counts are wrong.', resetTokenCache);
}