π οΈ ToolsTiktokenOn this pageTiktoken Problemβ How to compute the number of tokens in a prompt with tiktoken ? Solutionβ import tiktokenencoding = tiktoken.encoding_for_model("gpt-4")prompt_encoded = encoding.encode(prompt)nb_tokens = len(prompt_encoded)