B4J Question Counting Tokens for OpenAI

Tim Chapman

Active Member
Licensed User
Longtime User
I need to be able to count tokens in a user's text submission (before it is submitted) to OpenAI API.

I have researched and found that TikToken is the best way to do that.
There are two TikToken libraries available at this time. One is in Python. The other in Node.js. Those are shown here:

What is the easiest way for me to get TikToken into B4J?

The closest I have seen is to compile a Node.js project into a jar file as shown here:

This looks like the correct JS code to work with:

Any better answers anyone can see for this? Doing the conversion using the instructions above is a bit out of my league.
 

jkhazraji

Active Member
Licensed User
Longtime User
Send the text directly to the OpenAI API although it will consume your quota.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top