File size: 156 Bytes
d91a750
 
 
 
 
1
2
3
4
5
import tiktoken

def count_num_tokens(text: str, model: str) -> int:
    encoding = tiktoken.encoding_for_model(model)
    return len(encoding.encode(text))