UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

147 lines (146 loc) • 5.31 kB
import type { ProviderModelTokenLimit, ProviderTokenLimitTables } from "../types/index.js"; /** * Token Limit Constants for NeuroLink * * Centralized token configuration to replace magic numbers throughout the codebase. * Includes model-specific token limits, use-case optimized limits, and provider constraints. * * @fileoverview Token constants for AI model interactions * @author NeuroLink Team * @version 1.0.0 */ /** * Standard token limit categories * General-purpose token limits for different use cases */ export declare const TOKEN_LIMITS: { /** Conservative limits (reliable across all models) */ readonly CONSERVATIVE: 4096; /** Standard limits (most modern models) */ readonly STANDARD: 8192; /** High-capacity limits (premium models) */ readonly HIGH_CAPACITY: 16384; /** Large context windows (specialized models) */ readonly LARGE_CONTEXT: 100000; /** Ultra-large context windows (latest models) */ readonly ULTRA_LARGE_CONTEXT: 200000; /** Maximum context for any model */ readonly MAXIMUM_CONTEXT: 2097152; }; /** * Use-case specific token limits * Optimized token limits for different application scenarios */ export declare const USE_CASE_TOKENS: { /** Quick evaluation tasks */ readonly EVALUATION: 500; /** Analysis operations */ readonly ANALYSIS: 800; /** Summary generation */ readonly SUMMARY: 1000; /** Documentation generation */ readonly DOCUMENTATION: 12000; /** Code generation */ readonly CODE_GENERATION: 4000; /** Creative writing */ readonly CREATIVE_WRITING: 6000; /** Translation tasks */ readonly TRANSLATION: 2000; /** Conversation responses */ readonly CONVERSATION: 2048; /** Technical explanations */ readonly TECHNICAL_EXPLANATION: 3000; /** Research tasks */ readonly RESEARCH: 8000; }; export declare const PROVIDER_TOKEN_LIMITS: ProviderTokenLimitTables; /** * Context window sizes for different models * Maximum input token limits (separate from output limits) */ export declare const CONTEXT_WINDOWS: { /** Small context models */ readonly SMALL: 4096; /** Medium context models */ readonly MEDIUM: 32768; /** Large context models */ readonly LARGE: 128000; /** Ultra-large context models */ readonly ULTRA_LARGE: 1048576; /** Maximum theoretical context */ readonly MAXIMUM: 2097152; }; /** * Model-specific token limits with input/output breakdown * For models that require explicit input and output token limits; from the * `modelTokenLimits` section of `src/lib/providers/rules/limits.json`. */ export declare const MODEL_TOKEN_LIMITS: Record<string, ProviderModelTokenLimit>; /** * Token estimation utilities * Rough estimates for token counting without full tokenization */ export declare const TOKEN_ESTIMATION: { /** Average characters per token (English) */ readonly CHARS_PER_TOKEN: 4; /** Average words per token */ readonly WORDS_PER_TOKEN: 0.75; /** Code characters per token (more compact) */ readonly CODE_CHARS_PER_TOKEN: 3; /** Safety margin for token estimates */ readonly SAFETY_MARGIN: 0.8; }; /** * Token utility functions */ export declare const TokenUtils: { /** * Get safe token limit for a specific provider and model * @param provider - Provider name * @param model - Model name (optional) * @returns Safe token limit for the provider/model */ readonly getProviderTokenLimit: (provider: string, model?: string) => number; /** * Get token limit for specific use case * @param useCase - Use case type * @returns Appropriate token limit */ readonly getUseCaseTokenLimit: (useCase: keyof typeof USE_CASE_TOKENS) => number; /** * Estimate token count from text * @param text - Input text * @param isCode - Whether the text is code (more compact tokenization) * @returns Estimated token count */ readonly estimateTokenCount: (text: string, isCode?: boolean) => number; /** * Check if text exceeds token limit * @param text - Input text * @param limit - Token limit to check against * @param isCode - Whether the text is code * @returns True if text exceeds limit */ readonly exceedsTokenLimit: (text: string, limit: number, isCode?: boolean) => boolean; /** * Get appropriate token limit category * @param estimatedTokens - Estimated token count * @returns Token limit category */ readonly getTokenLimitCategory: (estimatedTokens: number) => keyof typeof TOKEN_LIMITS; /** * Truncate text to fit within token limit * @param text - Input text * @param tokenLimit - Maximum tokens allowed * @param isCode - Whether the text is code * @returns Truncated text */ readonly truncateToTokenLimit: (text: string, tokenLimit: number, isCode?: boolean) => string; }; export declare const DEFAULT_MAX_TOKENS: 8192; export declare const DEFAULT_EVALUATION_MAX_TOKENS: 500; export declare const DEFAULT_ANALYSIS_MAX_TOKENS: 800; export declare const DEFAULT_DOCUMENTATION_MAX_TOKENS: 12000; export declare const ANTHROPIC_SAFE: number; export declare const OPENAI_STANDARD: number; export declare const GOOGLE_STANDARD: number;