mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#709 Add extra type safety for token counting
This commit is contained in:
@@ -552,6 +552,10 @@ async function getClientVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTokenCount(str, padding = undefined) {
|
function getTokenCount(str, padding = undefined) {
|
||||||
|
if (typeof str !== 'string') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
let tokenizerType = power_user.tokenizer;
|
let tokenizerType = power_user.tokenizer;
|
||||||
|
|
||||||
if (main_api === 'openai') {
|
if (main_api === 'openai') {
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ export async function parseJsonFile(file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getStringHash(str, seed = 0) {
|
export function getStringHash(str, seed = 0) {
|
||||||
|
if (typeof str !== 'string') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
let h1 = 0xdeadbeef ^ seed,
|
let h1 = 0xdeadbeef ^ seed,
|
||||||
h2 = 0x41c6ce57 ^ seed;
|
h2 = 0x41c6ce57 ^ seed;
|
||||||
for (let i = 0, ch; i < str.length; i++) {
|
for (let i = 0, ch; i < str.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user