UNPKG

ai-patterns

Version:

Production-ready TypeScript patterns to build solid and robust AI applications. Retry logic, circuit breakers, rate limiting, human-in-the-loop escalation, prompt versioning, response validation, context window management, and more—all with complete type

34 lines 1.19 kB
/** * Smart Context Window Management Pattern * * Automatically manages context token limits by truncating, summarizing, * or chunking content to prevent context_length_exceeded errors. * * @example * ```typescript * import { smartContextWindow, ContextStrategy } from 'ai-patterns'; * * const result = await smartContextWindow({ * execute: async (messages) => { * return await generateText({ * model: openai('gpt-4-turbo'), * messages * }); * }, * messages: conversationHistory, * maxTokens: 120000, * strategy: ContextStrategy.SLIDING_WINDOW, * keepRecentCount: 50 * }); * ``` */ import type { SmartContextWindowConfig, SmartContextWindowResult, Message } from "../types/context-window"; /** * Smart context window management */ export declare function smartContextWindow<TResult = any>(config: SmartContextWindowConfig<TResult>): Promise<SmartContextWindowResult<TResult>>; /** * Helper function to create a summarizer using an AI model */ export declare function createAISummarizer(summarizeFn: (messages: Message[]) => Promise<string>): (messages: Message[]) => Promise<string>; //# sourceMappingURL=context-window.d.ts.map