( message: string, model = modelName )
| 236 | * @returns Promise that resolves to the token count |
| 237 | */ |
| 238 | export 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 |
no test coverage detected