UNPKG

cag-js

Version:

Chunked Augmented Generation (CAG) algorithm for processing large text inputs with AI models

39 lines (38 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateConfig = exports.prepare_prompt = void 0; /** * Prepares a prompt by replacing a placeholder with the actual text * @param template The prompt template with {text} placeholder * @param text The text to insert into the template * @returns Prepared prompt string */ const prepare_prompt = (template, text) => { return template.replace('{text}', text); }; exports.prepare_prompt = prepare_prompt; /** * Validates the CAG configuration * @param config The CAG configuration object * @throws Error if configuration is invalid */ const validateConfig = (config) => { if (config.chunkSize < 1) { throw new Error("chunkSize must be greater than 0"); } if (config.chunkOverlap < 0) { throw new Error("chunkOverlap must be greater than or equal to 0"); } if (config.iteration_limit) { if (config.iteration_limit < 2) { throw new Error("iteration_limit must be greater than 1"); } if (config.iteration_limit > 100) { throw new Error("iteration_limit must be less than or equal to 100"); } } if (config.iteration_output_token_limit && config.iteration_output_token_limit < 1) { throw new Error("iteration_output_token_limit must be greater than 0"); } }; exports.validateConfig = validateConfig;