jodendaal/OpenAI.Net

Add calculate tokens helper

Opened this issue · 2 comments

Add method that will calculate tokens a request will use for text completion and chat API.

This is useful when consuming the library in an application and needing to truncate prompt.

Help avoid each implementation using a different calculation.

That would be very helpful. I keep getting exceptions because the input size + the maxtokens param exceed the models max token count.

Bit late to the party, but you can use TikTokenSharp for this (port of the tiktoken python library)