GPTcord/src/tokenCounter.ts
Wroclaw 2a38ae4a95 Limit sent chat to 2048 tokens.
This also solves the issue where we would request more tokens,
than the model is capable of (over 4096)
2023-03-19 09:11:37 +01:00

5 lines
135 B
TypeScript

import { encode } from "gpt-3-encoder";
export default function countTokens(text: string): number {
return encode(text).length;
}