import { encode } from 'gpt-tokenizer' /** * Returns the number of tokens in a prompt. Tokens are the smallest unit of text that OpenAI's API processes. * @param prompt The prompt to get the number of tokens from * @returns The number of tokens in the prompt */ function getNumberOfTokensInPrompt(prompt: string) { const encodedPrompt = encode(prompt) return encodedPrompt.length } export { getNumberOfTokensInPrompt }