Retry API tokenization on reconnecting to backend Fixes #5004

7e410b4aa8e0d5e4fd903a55564a8c6f8054a269

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

1 files changed, +7 -1Showing whitespace changes
public/scripts/tokenizers.js+7 -1
@@ -1,5 +1,5 @@
11import { localforage } from '../lib.js';
22import { characters, event_types, eventSource, main_api, nai_settings, online_status, this_chid } from '../script.js';
33import { power_user, registerDebugFunction } from './power-user.js';
44import { chat_completion_sources, model_list, oai_settings } from './openai.js';
55import { groups, selected_group } from './group-chats.js';
@@ -1223,6 +1223,12 @@ export async function initTokenizers() {
12231223 textgen_types.VLLM,
12241224 textgen_types.APHRODITE,
12251225 );
1226+ eventSource.on(event_types.ONLINE_STATUS_CHANGED, async () => {
1227+ // Clear tokenizer warning when (re)connecting to an LLM backend that supports tokenization
1228+ if (main_api === 'textgenerationwebui' && TEXTGEN_TOKENIZERS.includes(textgen_settings.type)) {
1229+ sessionStorage.removeItem(TOKENIZER_WARNING_KEY);
1230+ }
1231+ });
12261232 await loadTokenCache();
12271233 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);
12281234}