MCPcopy
hub / github.com/msgbyte/tianji / calcOpenAIToken

Function calcOpenAIToken

src/server/model/openai.ts:238–255  ·  view source on GitHub ↗
(
  message: string,
  model = modelName
)

Source from the content-addressed store, hash-verified

236 * @returns Promise that resolves to the token count
237 */
238export function calcOpenAIToken(
239 message: string,
240 model = modelName
241): Promise<number> {
242 return tokenCalcQueue.enqueue(
243 () => {
244 return new Promise<number>((resolve, reject) => {
245 try {
246 const count = calcOpenAITokenSync(message, model);
247 resolve(count);
248 } catch (error) {
249 reject(error);
250 }
251 });
252 },
253 { message, model }
254 );
255}
256
257/**
258 * Synchronous version of calcOpenAIToken for backward compatibility

Callers 5

groupByTokenSizeFunction · 0.85
calcMessagesTokenFunction · 0.85
buildOpenAIHandlerFunction · 0.85
ai.tsFile · 0.85

Calls 2

calcOpenAITokenSyncFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected