-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
How to calculate token size from string? #1962
Comments
You could use |
I'm using Whisper.cpp's C API from Swift. But I now see that I could use So my request is to add something like this: int whisper_token_count(struct whisper_context * ctx, const char * text) {
const auto res = tokenize(ctx->vocab, text);
return res.size();
} |
Your request is a bit too specific imo. You can create a function like that yourself, just disregard the tokens after you've checked the size. |
Any app accepting a custom prompt will need this. Of course every app could reinvent the wheel, but I think many app developers don't even realize they have to validate the prompt. I for sure did not. Having a specific function like this makes it more discoverable that they need to. |
I'm using the
params.initial_prompt
setting in my app, and I would like to interactively warn the user if they exceed the prompt limit. Given a string, how can I calculate the token size?The text was updated successfully, but these errors were encountered: