-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise error when concurrent to call new Tiktoken #70
Comments
I think the problem is that I think the second call should wait until the first call finished the init process install of skip at once. |
This is a demo code to trigger this error: const tiktokenModel = require("tiktoken/encoders/cl100k_base.json");
const { Tiktoken, init } = require("tiktoken/lite/init");
const fs = require('fs')
const wasm = fs.readFileSync("./node_modules/tiktoken/lite/tiktoken_bg.wasm");
async function test() {
await init((imports) => WebAssembly.instantiate(wasm, imports));
encoding = new Tiktoken(
tiktokenModel.bpe_ranks,
tiktokenModel.special_tokens,
tiktokenModel.pat_str
)
const tokens = encoding.encode("hello world");
console.log(tokens)
encoding.free();
}
async function main() {
a = test()
b = test()
await Promise.all([a, b])
}
main() the error message is: /Users/qkxie/Project/test_tiktoken/node_modules/tiktoken/lite/tiktoken_bg.cjs:393
throw new Error(getStringFromWasm0(arg0, arg1));
^
Error: `unwrap_throw` failed
at module.exports.__wbindgen_throw (/Users/qkxie/Project/test_tiktoken/node_modules/tiktoken/lite/tiktoken_bg.cjs:393:11)
at wasm://wasm/003425c2:wasm-function[863]:0x78e3c
at wasm://wasm/003425c2:wasm-function[567]:0x6f758
at wasm://wasm/003425c2:wasm-function[8]:0x3aaa
at new Tiktoken (/Users/qkxie/Project/test_tiktoken/node_modules/tiktoken/lite/tiktoken_bg.cjs:179:26)
at test (/Users/qkxie/Project/test_tiktoken/index.js:10:16)
at async Promise.all (index 0)
at async main (/Users/qkxie/Project/test_tiktoken/index.js:24:5)
Node.js v20.5.1 |
The context code is https://github.com/mckaywrigley/chatbot-ui/blob/main/pages/api/chat.ts#L21
The key problem is here:
In my frontend, I use promise.all to send 3 requests simultaneously to this backend API. I have noticed the following phenomena:
The text was updated successfully, but these errors were encountered: