Add lazy loading of sentencepiece tokenizers

This commit is contained in:
Cohee
2023-11-15 19:39:55 +02:00
parent 9199750afe
commit 3fb26d3927
2 changed files with 73 additions and 48 deletions

View File

@@ -2795,13 +2795,13 @@ app.post("/openai_bias", jsonParser, async function (request, response) {
if (sentencepieceTokenizers.includes(model)) {
const tokenizer = getSentencepiceTokenizer(model);
encodeFunction = (text) => new Uint32Array(tokenizer.encodeIds(text));
const instance = await tokenizer?.get();
encodeFunction = (text) => new Uint32Array(instance?.encodeIds(text));
} else {
const tokenizer = getTiktokenTokenizer(model);
encodeFunction = (tokenizer.encode.bind(tokenizer));
}
for (const entry of request.body) {
if (!entry || !entry.text) {
continue;