Last active
September 13, 2023 08:59
-
-
Save EnkrateiaLucca/e1d501424d1a1e350762ec5eedc275ca to your computer and use it in GitHub Desktop.
Calculates number of tokens
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 | |
def get_num_tokens(prompt, model="gpt-3.5-turbo"): | |
"""Calculates the number of tokens in a text prompt""" | |
enc = tiktoken.encoding_for_model("gpt-3.5-turbo") | |
return len(enc.encode(prompt)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment