File size: 570 Bytes
c2c8c8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { estimateTokens } from '@glmpilot/shared';
import { logger } from './logger.js';

/**
 * Estimate token count and warn if approaching limits.
 */
export function countTokens(text: string, context?: string): number {
  const count = estimateTokens(text);
  if (count > 25000) {
    logger.warn(`High token count: ~${count} tokens${context ? ` for ${context}` : ''}`);
  }
  return count;
}

/**
 * Check if text would exceed a token limit.
 */
export function wouldExceedTokenLimit(text: string, limit: number): boolean {
  return estimateTokens(text) > limit;
}