Retry API tokenization on reconnecting to backend Fixes #5004
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import { localforage } from '../lib.js'; |
| 2 | 2 | import { characters, event_types, eventSource, main_api, nai_settings, online_status, this_chid } from '../script.js'; |
| 3 | 3 | import { power_user, registerDebugFunction } from './power-user.js'; |
| 4 | 4 | import { chat_completion_sources, model_list, oai_settings } from './openai.js'; |
| 5 | 5 | import { groups, selected_group } from './group-chats.js'; |
| @@ -1223,6 +1223,12 @@ export async function initTokenizers() { | ||
| 1223 | 1223 | textgen_types.VLLM, |
| 1224 | 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 | 1232 | await loadTokenCache(); |
| 1227 | 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 | } |