Last active
April 19, 2023 19:18
-
-
Save amrakm/f48a19049db606b8b4f062b708dc7ff8 to your computer and use it in GitHub Desktop.
gpt token counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tiktoken | |
tokenizer = tiktoken.get_encoding('p50k_base') | |
# create the length function | |
def tiktoken_len(text): | |
tokens = tokenizer.encode( | |
text, | |
disallowed_special=() | |
) | |
return len(tokens) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment