Can the SDK tell me the number of input tokens a message will consume before sending? #1177
Unanswered
danelliottster
asked this question in
Q&A
Replies: 1 comment
-
Yes you can using tiktoken. This will estimate the number of tokens your request will send.
Here's the doc: https://pypi.org/project/tiktoken/ Simply call this function in a while loop and reduce the length of your prompt in the loop until you fit within your token limit. I also usually allow for some room between the limit and what I send (95% of 4096 for instance) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to include as much information as possible to the LLM without exceeding the input token limit. Can I tell, exactly, how many tokens an input message will be prior to sending the request?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions