mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-03 03:17:54 +01:00
Silently redirect tokenization to the next matching tokenizer
This commit is contained in:
parent
ba52ceb979
commit
8c5b02d2ea
@ -923,15 +923,20 @@ function countTokensFromTextgenAPI(str, resolve) {
|
|||||||
|
|
||||||
function apiFailureTokenCount(str) {
|
function apiFailureTokenCount(str) {
|
||||||
console.error('Error counting tokens');
|
console.error('Error counting tokens');
|
||||||
|
let shouldTryAgain = false;
|
||||||
|
|
||||||
if (!sessionStorage.getItem(TOKENIZER_WARNING_KEY)) {
|
if (!sessionStorage.getItem(TOKENIZER_WARNING_KEY)) {
|
||||||
toastr.warning(
|
const bestMatchBefore = getTokenizerBestMatch(main_api);
|
||||||
'Your selected API doesn\'t support the tokenization endpoint. Using estimated counts.',
|
|
||||||
'Error counting tokens',
|
|
||||||
{ timeOut: 10000, preventDuplicates: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
sessionStorage.setItem(TOKENIZER_WARNING_KEY, String(true));
|
sessionStorage.setItem(TOKENIZER_WARNING_KEY, String(true));
|
||||||
|
const bestMatchAfter = getTokenizerBestMatch(main_api);
|
||||||
|
if ([tokenizers.API_TEXTGENERATIONWEBUI, tokenizers.API_KOBOLD].includes(bestMatchBefore) && bestMatchBefore !== bestMatchAfter) {
|
||||||
|
shouldTryAgain = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only try again if we guarantee not to be looped by the same error
|
||||||
|
if (shouldTryAgain && power_user.tokenizer === tokenizers.BEST_MATCH) {
|
||||||
|
return getTokenCount(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
return guesstimate(str);
|
return guesstimate(str);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user