This will improve the performance of indexing when using a GPT model. Also, improved the Async interface to also have an async decode method. Note: I was only able to test this method with the test I added as I do not have access to a GPT model. Co-authored-by: Rob Leidle <rleidle@tesla.com>
17 lines
No EOL
361 B
JavaScript
17 lines
No EOL
361 B
JavaScript
import workerpool from "workerpool";
|
|
import { encodingForModel as _encodingForModel } from "js-tiktoken";
|
|
|
|
const tiktokenEncoding = _encodingForModel("gpt-4");
|
|
|
|
function encode(text) {
|
|
return tiktokenEncoding.encode(text, "all", []);
|
|
}
|
|
|
|
function decode(tokens) {
|
|
return tiktokenEncoding.decode(tokens);
|
|
}
|
|
|
|
workerpool.worker({
|
|
decode,
|
|
encode,
|
|
}); |