/** * An alternative to template literals that allows for capturing the name of the * variables involved, and doing variable substitution at a later time. * * This is used for prompts where you want the same prompt but swap out certain values. * * Example: * * ``` * const template = f`Hello {name}!`; * * // exposes the following: * template.variables; // ["name"] * template[formatProp]({name: "World"}); // "Hello World!" * template[templateProp]; // "Hello {name}!" * ``` * * * @param strings The string parts passed to the template literal * @returns An object with the following properties: * - `variables`: The names of the variables used in the template * - `format`: A function that takes a dictionary of variable names to values, and returns the formatted string * - `template`: The original template string * @throws If the template literal contains any inline variables (e.g. `${name}` instead of `{name}`) */ export declare function f(strings: TemplateStringsArray | string, ...inlineVariables: any[]): { [formatProp]: (parameters: Record) => string; [variablesProp]: readonly string[]; [templateProp]: string; }; declare const formatProp: unique symbol; declare const templateProp: unique symbol; declare const variablesProp: unique symbol; export declare function formatTemplate(o: ObjectTemplate, parameters: Record): T; export declare function getTemplate(o: ObjectTemplate): T; export declare function getTemplateVariables(o: ObjectTemplate): readonly string[]; /** * A template for nested objects, most useful when constructing chat prompts. */ export interface ObjectTemplate_ { /** * A function that takes a dictionary of variable names to values, and returns the formatted object */ [formatProp]: (parameters: Record) => T; /** * The names of the variables used in the template */ [variablesProp]: readonly string[]; /** * The original template object */ [templateProp]: T; } export type ObjectTemplate = T extends string ? ObjectTemplate_ : ObjectTemplate_ & T; /** * A template for nested objects, most useful when constructing chat prompts. * * Example: * * ``` * const template = objectTemplate([{ * "role": "user", * "content": f`Hello {name}!` * }]); * * // exposes the following: * template[variablesProp]; // ["name"] * template[formatProp]({name: "World"}); // [{role: "user", content: "Hello World!"}] * template[templateProp]; // [{role: "user", content: "Hello {name}!"}] * ``` * * @param objs The object to template * @returns An object with the following properties: * - `variables`: The names of the variables used in the template * - `format`: A function that takes a dictionary of variable names to values, and returns the formatted object * - `template`: The original template object * @throws If the template literal contains any inline variables (e.g. `${name}` instead of `{name}`) */ export declare function objectTemplate(objs: T): ObjectTemplate; export declare function isObjectTemplate(obj: any): obj is ObjectTemplate; export {};