Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve token cost calculation (+performance) #8

Open
Shackless opened this issue Mar 23, 2023 · 2 comments
Open

Improve token cost calculation (+performance) #8

Shackless opened this issue Mar 23, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@Shackless
Copy link
Contributor

Shackless commented Mar 23, 2023

SlickGPT uses gpt3-tokenizer which is one of the few libs I found that "just runs" in the browser. It's close enough but not perfect as the calculations in

export function estimateChatCost(chat: Chat): ChatCost {
are a bit "off" compared to the official OpenAI Tokenizer.

Another and bigger problem is performance. The gpt3-tokenizer has a huge payload and it's pretty slow. Other solutions use advanced stuff like Node Buffer structures and are much faster. The problem is that they don't run easily in the browser without Node.

Any ideas how to calculate the tokens per Chat (context, prompts, completions) more accurately and faster?

@Shackless Shackless added the help wanted Extra attention is needed label Mar 23, 2023
@Shackless Shackless changed the title Improve token cost calculation Improve token cost calculation (+performance) Mar 29, 2023
@rarestg
Copy link

rarestg commented Apr 24, 2023

The official Tokenizer cites this package: https://www.npmjs.com/package/gpt-3-encoder
... or is this one of the libs that doesn't "just run" in the browser?

@Shackless
Copy link
Contributor Author

The official Tokenizer cites this package: https://www.npmjs.com/package/gpt-3-encoder ... or is this one of the libs that doesn't "just run" in the browser?

Yeah, unfortunately this one requires a full node environment to run. We COULD use Vercel functions for that but I don't think it's worth it and would rather leave the token calculation to the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants