Retry API tokenization on reconnecting to backend Fixes #5004

7e410b4aa8e0d5e4fd903a55564a8c6f8054a269

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

1 files changed, +7 -1Ignore whitespace
public/scripts/tokenizers.js+7 -1
@@ -1,5 +1,5 @@
1import { localforage } from '../lib.js';1import { localforage } from '../lib.js';
2import { characters, main_api, nai_settings, online_status, this_chid } from '../script.js';2import { characters, event_types, eventSource, main_api, nai_settings, online_status, this_chid } from '../script.js';
3import { power_user, registerDebugFunction } from './power-user.js';3import { power_user, registerDebugFunction } from './power-user.js';
4import { chat_completion_sources, model_list, oai_settings } from './openai.js';4import { chat_completion_sources, model_list, oai_settings } from './openai.js';
5import { groups, selected_group } from './group-chats.js';5import { groups, selected_group } from './group-chats.js';
@@ -1223,6 +1223,12 @@ export async function initTokenizers() {
1223 textgen_types.VLLM,1223 textgen_types.VLLM,
1224 textgen_types.APHRODITE,1224 textgen_types.APHRODITE,
1225 );1225 );
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 });
1226 await loadTokenCache();1232 await loadTokenCache();
1227 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);1233 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);
1228}1234}