UNPKG

react-native-executorch

Version:

An easy way to run AI models in React Native with ExecuTorch

32 lines (30 loc) 1.18 kB
"use strict"; /** * A simple context strategy that retains a fixed number of the most recent messages. * This strategy trims the conversation history based purely on the message count. * @category Utils */ export class MessageCountContextStrategy { /** * Initializes the MessageCountContextStrategy. * @param windowLength - The maximum number of recent messages to retain in the context. Defaults to 5. */ constructor(windowLength = 5) { this.windowLength = windowLength; } /** * Builds the context by slicing the history to retain only the most recent `windowLength` messages. * @param systemPrompt - The top-level instructions for the model. * @param history - The complete conversation history. * @param _maxContextLength - Unused in this strategy. * @param _getTokenCount - Unused in this strategy. * @returns The truncated message history with the system prompt at the beginning. */ buildContext(systemPrompt, history, _maxContextLength, _getTokenCount) { return [{ content: systemPrompt, role: 'system' }, ...history.slice(-this.windowLength)]; } } //# sourceMappingURL=MessageCountContextStrategy.js.map