zmedelis / bosquet

Tooling to build LLM applications: prompt templating and composition, agents, LLM memory, and other instruments for builders of AI applications.
https://zmedelis.github.io/bosquet/
Eclipse Public License 1.0
277 stars 18 forks source link

api based implementation of token-count-fn #5

Closed behrica closed 1 year ago

behrica commented 1 year ago

As there is no JVM code for GPT token ccount, I was wondering if we could not add an token-count-fn which uses a "hosted token count function". I found one here: https://rapidapi.com/galim-galim-default/api/openai-gpt-pricing-calculator

A "user" of this function needed to subscribe to rapidapi to use it, but 100 calls per day are for free. In practice the method signature of a rapidapi-gpt-token-count-fn would then taken the users API key as input and then simply make an http call :

curl --request POST \
        --url https://openai-gpt-pricing-calculator.p.rapidapi.com/chat \
        --header 'X-RapidAPI-Host: openai-gpt-pricing-calculator.p.rapidapi.com' \
        --header 'X-RapidAPI-Key: <<users key>>> \
        --header 'content-type: application/json' \
        --data '{
    "model": "gpt-3.5-turbo",
    "content": "Hey there. How are you doing today? Answer with a Steve Jobs style."
}'

which returns the number of tokens.

What do you think ?

behrica commented 1 year ago

I saw there is now https://github.com/knuddelsgmbh/jtokkit, so we don't need this any more