UNPKG

@langchain/core

Version:
1 lines 10.2 kB
{"version":3,"file":"prompt.d.cts","names":["BaseStringPromptTemplate","BasePromptTemplateInput","TypedPromptInputValues","TemplateFormat","SerializedPromptTemplate","InputValues","PartialValues","MessageContent","ContentBlock","PromptTemplateInput","RunInput","PartialVariableName","Format","NonAlphanumeric","ExtractTemplateParamsRecursive","T","Param","Rest","Result","ParamsFromFString","Record","ExtractedFStringParams","Symbol","PromptTemplate","Promise","Omit","NewPartialVariableName","Extract","Exclude"],"sources":["../../src/prompts/prompt.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type { BasePromptTemplateInput, TypedPromptInputValues } from \"./base.js\";\nimport { type TemplateFormat } from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any, Format extends TemplateFormat = TemplateFormat> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n}\ntype NonAlphanumeric = \" \" | \"\\t\" | \"\\n\" | \"\\r\" | '\"' | \"'\" | \"{\" | \"[\" | \"(\" | \"`\" | \":\" | \";\";\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;\nexport type ParamsFromFString<T extends string> = {\n [Key in ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\nexport type ExtractedFStringParams<T extends string, RunInput extends InputValues = Symbol> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport declare class PromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends BaseStringPromptTemplate<RunInput, PartialVariableName> implements PromptTemplateInput<RunInput, PartialVariableName> {\n static lc_name(): string;\n template: MessageContent;\n templateFormat: TemplateFormat;\n validateTemplate: boolean;\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>);\n _getPromptType(): \"prompt\";\n /**\n * Formats the prompt template with the provided values.\n * @param values The values to be used to format the prompt template.\n * @returns A promise that resolves to a string which is the formatted prompt.\n */\n format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(examples: string[], suffix: string, inputVariables: string[], exampleSeparator?: string, prefix?: string): PromptTemplate<any, any>;\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"f-string\">, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"mustache\">, \"template\" | \"inputVariables\">): PromptTemplate<InputValues>;\n /**\n * Partially applies values to the prompt template.\n * @param values The values to be partially applied to the prompt template.\n * @returns A new instance of PromptTemplate with the partially applied values.\n */\n partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<PromptTemplate<InputValues<Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>>, any>>;\n serialize(): SerializedPromptTemplate;\n static deserialize(data: SerializedPromptTemplate): Promise<PromptTemplate>;\n}\nexport {};\n"],"mappings":";;;;;;;;;;;AAYA;;;AAIyDG,UAJxCM,mBAIwCN;;iBAFxCE,WAEyGK,GAAAA,GAAAA;;4BAI5GH,MAAAA,GAAAA,GAAAA,EAAAA,eAJ2CJ,cAI3CI,GAJ4DJ,cAI5DI,CAAAA,SAJoFN,uBAIpFM,CAJ4GG,QAI5GH,EAJsHI,mBAItHJ,CAAAA,CAAAA;EAAc;;;EAJ6F,QAAA,EAI3GA,cAJ2G;EAsBpHM;AAAe;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