(prompt: ChatGPTMessage[] | string)
| 129 | } |
| 130 | |
| 131 | export function getTokenCount(prompt: ChatGPTMessage[] | string): number { |
| 132 | let chatGptMessages: ChatMessage[]; |
| 133 | if (typeof prompt === "string") { |
| 134 | chatGptMessages = [{ role: "user", content: prompt }]; |
| 135 | } else { |
| 136 | chatGptMessages = prompt as ChatMessage[]; |
| 137 | } |
| 138 | // Per the docs, the tokenizer should be the same for 3.5-turbo and 4. |
| 139 | const encoded = tokenizer.encodeChat(chatGptMessages, "gpt-4"); |
| 140 | return encoded.length; |
| 141 | } |
| 142 | |
| 143 | export function chunkString( |
| 144 | text: string, |
no outgoing calls
no test coverage detected