Can the SDK tell me the number of input tokens a message will consume before sending? #1177
Replies: 1 comment 1 reply
|
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) |
|
Not exactly from the SDK alone. For a preflight estimate, the usual tool is For the exact number actually used, inspect The practical workflow is:
So: exact before send = generally no; good estimate before send = yes. |
Uh oh!
There was an error while loading. Please reload this page.
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.
All reactions