openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Compute nb of tokens for a prompt

Open ccolas opened this issue 1 year ago • 0 comments

Hi, Is there a way to compute the number of tokens in the prompt before sending a request (in python)? I'd like to avoid the "too many tokens" error by setting max_token to 4097 - nb_tokens(prompt)

Thanks!

ccolas avatar Nov 23 '22 18:11 ccolas