jddev273 / streamed-chatgpt-api

A node module for streaming API responses from the ChatGPT APi.
MIT License
30 stars 6 forks source link

How can I get the number of tokens a user spent for each chat request? #1

Closed ziziele closed 1 year ago

jddev273 commented 1 year ago

You'll need to calculate the number with a library like tiktoken which calculates the number of tokens in a string (or you can get a rough count by counting the number of spaces and punctuation).

Here's a node module binding tiktoken: https://www.npmjs.com/package/@dqbd/tiktoken