Skip to content
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

Expose more ctx->vocab interfaces. #2690

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/whisper.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ extern "C" {
WHISPER_API const char * whisper_token_to_str(struct whisper_context * ctx, whisper_token token);
WHISPER_API const char * whisper_model_type_readable(struct whisper_context * ctx);

// String -> Token Id. Uses the vocabulary in the provided context
WHISPER_API bool whisper_token_exists(struct whisper_context * ctx, const char * str);
WHISPER_API whisper_token whisper_str_to_token(struct whisper_context * ctx, const char * str);

// Special tokens
WHISPER_API whisper_token whisper_token_eot (struct whisper_context * ctx);
Expand Down
8 changes: 8 additions & 0 deletions src/whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4068,6 +4068,14 @@ const char * whisper_token_to_str(struct whisper_context * ctx, whisper_token to
return ctx->vocab.id_to_token.at(token).c_str();
}

whisper_token whisper_str_to_token(struct whisper_context * ctx, const char * str) {
return ctx->vocab.token_to_id.at(str);
}

bool whisper_token_exists(struct whisper_context * ctx, const char * str) {
return ctx->vocab.token_to_id.find(str) != ctx->vocab.token_to_id.end();
}

whisper_token whisper_token_eot(struct whisper_context * ctx) {
return ctx->vocab.token_eot;
}
Expand Down
Loading