MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / getTokenCount

Function getTokenCount

lib/utils.ts:131–141  ·  view source on GitHub ↗
(prompt: ChatGPTMessage[] | string)

Source from the content-addressed store, hash-verified

129}
130
131export 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
143export function chunkString(
144 text: string,

Callers 9

PageActionsSectionFunction · 0.90
splitIntoTextChunksFunction · 0.90
joinShortChunksFunction · 0.90
hideLongGraphOutputsFunction · 0.90
BertieFunction · 0.90
chatHistorySummaryPromptFunction · 0.90
AngelaFunction · 0.90
openAiCostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected