| 923 | | 923 | |
| 924 | function apiFailureTokenCount(str) { | 924 | function apiFailureTokenCount(str) { |
| 925 | console.error('Error counting tokens'); | 925 | console.error('Error counting tokens'); |
| | 926 | let shouldTryAgain = false; |
| 926 | | 927 | |
| 927 | if (!sessionStorage.getItem(TOKENIZER_WARNING_KEY)) { | 928 | if (!sessionStorage.getItem(TOKENIZER_WARNING_KEY)) { |
| 928 | toastr.warning( | 929 | const bestMatchBefore = getTokenizerBestMatch(main_api); |
| 929 | 'Your selected API doesn\'t support the tokenization endpoint. Using estimated counts.', | | |
| 930 | 'Error counting tokens', | | |
| 931 | { timeOut: 10000, preventDuplicates: true }, | | |
| 932 | ); | | |
| 933 | | | |
| 934 | sessionStorage.setItem(TOKENIZER_WARNING_KEY, String(true)); | 930 | sessionStorage.setItem(TOKENIZER_WARNING_KEY, String(true)); |
| | 931 | const bestMatchAfter = getTokenizerBestMatch(main_api); |
| | 932 | if ([tokenizers.API_TEXTGENERATIONWEBUI, tokenizers.API_KOBOLD].includes(bestMatchBefore) && bestMatchBefore !== bestMatchAfter) { |
| | 933 | shouldTryAgain = true; |
| | 934 | } |
| | 935 | } |
| | 936 | |
| | 937 | // Only try again if we guarantee not to be looped by the same error |
| | 938 | if (shouldTryAgain && power_user.tokenizer === tokenizers.BEST_MATCH) { |
| | 939 | return getTokenCount(str); |
| 935 | } | 940 | } |
| 936 | | 941 | |
| 937 | return guesstimate(str); | 942 | return guesstimate(str); |