UNPKG

@langchain/core

Version:
1 lines 8.93 kB
{"version":3,"file":"few_shot.d.ts","names":["BaseStringPromptTemplate","BasePromptTemplateInput","TypedPromptInputValues","Example","BaseExampleSelector","TemplateFormat","PromptTemplate","SerializedFewShotTemplate","InputValues","PartialValues","BaseMessage","BaseChatPromptTemplate","BaseMessagePromptTemplate","FewShotPromptTemplateInput","FewShotPromptTemplate","NewPartialVariableName","Promise","FewShotChatMessagePromptTemplateInput","FewShotChatMessagePromptTemplate","RunInput","PartialVariableName"],"sources":["../../src/prompts/few_shot.d.ts"],"sourcesContent":["import { BaseStringPromptTemplate } from \"./string.js\";\nimport type { BasePromptTemplateInput, TypedPromptInputValues, Example } from \"./base.js\";\nimport type { BaseExampleSelector } from \"../example_selectors/base.js\";\nimport { type TemplateFormat } from \"./template.js\";\nimport { PromptTemplate } from \"./prompt.js\";\nimport type { SerializedFewShotTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { BaseMessage } from \"../messages/index.js\";\nimport { BaseChatPromptTemplate, type BaseMessagePromptTemplate } from \"./chat.js\";\nexport interface FewShotPromptTemplateInput extends BasePromptTemplateInput<InputValues> {\n /**\n * Examples to format into the prompt. Exactly one of this or\n * {@link exampleSelector} must be\n * provided.\n */\n examples?: Example[];\n /**\n * An {@link BaseExampleSelector} Examples to format into the prompt. Exactly one of this or\n * {@link examples} must be\n * provided.\n */\n exampleSelector?: BaseExampleSelector;\n /**\n * An {@link PromptTemplate} used to format a single example.\n */\n examplePrompt: PromptTemplate;\n /**\n * String separator used to join the prefix, the examples, and suffix.\n */\n exampleSeparator?: string;\n /**\n * A prompt template string to put before the examples.\n *\n * @defaultValue `\"\"`\n */\n prefix?: string;\n /**\n * A prompt template string to put after the examples.\n */\n suffix?: string;\n /**\n * The format of the prompt template. Options are: 'f-string'\n */\n templateFormat?: TemplateFormat;\n /**\n * Whether or not to try validating the template on initialization.\n */\n validateTemplate?: boolean;\n}\n/**\n * Prompt template that contains few-shot examples.\n * @augments BasePromptTemplate\n * @augments FewShotPromptTemplateInput\n * @example\n * ```typescript\n * const examplePrompt = PromptTemplate.fromTemplate(\n * \"Input: {input}\\nOutput: {output}\",\n * );\n *\n * const exampleSelector = await SemanticSimilarityExampleSelector.fromExamples(\n * [\n * { input: \"happy\", output: \"sad\" },\n * { input: \"tall\", output: \"short\" },\n * { input: \"energetic\", output: \"lethargic\" },\n * { input: \"sunny\", output: \"gloomy\" },\n * { input: \"windy\", output: \"calm\" },\n * ],\n * new OpenAIEmbeddings(),\n * HNSWLib,\n * { k: 1 },\n * );\n *\n * const dynamicPrompt = new FewShotPromptTemplate({\n * exampleSelector,\n * examplePrompt,\n * prefix: \"Give the antonym of every input\",\n * suffix: \"Input: {adjective}\\nOutput:\",\n * inputVariables: [\"adjective\"],\n * });\n *\n * // Format the dynamic prompt with the input 'rainy'\n * console.log(await dynamicPrompt.format({ adjective: \"rainy\" }));\n *\n * ```\n */\nexport declare class FewShotPromptTemplate extends BaseStringPromptTemplate implements FewShotPromptTemplateInput {\n lc_serializable: boolean;\n examples?: InputValues[];\n exampleSelector?: BaseExampleSelector | undefined;\n examplePrompt: PromptTemplate;\n suffix: string;\n exampleSeparator: string;\n prefix: string;\n templateFormat: TemplateFormat;\n validateTemplate: boolean;\n constructor(input: FewShotPromptTemplateInput);\n _getPromptType(): \"few_shot\";\n static lc_name(): string;\n private getExamples;\n partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<FewShotPromptTemplate>;\n /**\n * Formats the prompt with the given values.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n format(values: InputValues): Promise<string>;\n serialize(): SerializedFewShotTemplate;\n static deserialize(data: SerializedFewShotTemplate): Promise<FewShotPromptTemplate>;\n}\nexport interface FewShotChatMessagePromptTemplateInput extends BasePromptTemplateInput<InputValues> {\n /**\n * Examples to format into the prompt. Exactly one of this or\n * {@link exampleSelector} must be\n * provided.\n */\n examples?: Example[];\n /**\n * An {@link BaseMessagePromptTemplate} | {@link BaseChatPromptTemplate} used to format a single example.\n */\n examplePrompt: BaseMessagePromptTemplate | BaseChatPromptTemplate;\n /**\n * String separator used to join the prefix, the examples, and suffix.\n *\n * @defaultValue `\"\\n\\n\"`\n */\n exampleSeparator?: string;\n /**\n * An {@link BaseExampleSelector} Examples to format into the prompt. Exactly one of this or\n * {@link examples} must be\n * provided.\n */\n exampleSelector?: BaseExampleSelector | undefined;\n /**\n * A prompt template string to put before the examples.\n *\n * @defaultValue `\"\"`\n */\n prefix?: string;\n /**\n * A prompt template string to put after the examples.\n *\n * @defaultValue `\"\"`\n */\n suffix?: string;\n /**\n * The format of the prompt template. Options are: 'f-string'\n *\n * @defaultValue `f-string`\n */\n templateFormat?: TemplateFormat;\n /**\n * Whether or not to try validating the template on initialization.\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\n}\n/**\n * Chat prompt template that contains few-shot examples.\n * @augments BasePromptTemplateInput\n * @augments FewShotChatMessagePromptTemplateInput\n */\nexport declare class FewShotChatMessagePromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends BaseChatPromptTemplate implements FewShotChatMessagePromptTemplateInput {\n lc_serializable: boolean;\n examples?: InputValues[];\n exampleSelector?: BaseExampleSelector | undefined;\n examplePrompt: BaseMessagePromptTemplate | BaseChatPromptTemplate;\n suffix: string;\n exampleSeparator: string;\n prefix: string;\n templateFormat: TemplateFormat;\n validateTemplate: boolean;\n _getPromptType(): \"few_shot_chat\";\n static lc_name(): string;\n constructor(fields: FewShotChatMessagePromptTemplateInput);\n private getExamples;\n /**\n * Formats the list of values and returns a list of formatted messages.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n formatMessages(values: TypedPromptInputValues<RunInput>): Promise<BaseMessage[]>;\n /**\n * Formats the prompt with the given values.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Partially formats the prompt with the given values.\n * @param values The values to partially format the prompt with.\n * @returns A promise that resolves to an instance of `FewShotChatMessagePromptTemplate` with the given values partially formatted.\n */\n partial(values: PartialValues<PartialVariableName>): Promise<FewShotChatMessagePromptTemplate<RunInput, PartialVariableName>>;\n}\n//# sourceMappingURL=few_shot.d.ts.map"],"mappings":";;;;;;;;;;;;UASiBa,0BAAAA,SAAmCZ,wBAAwBO;;;AAA5E;;;EAYsBJ,QAAAA,CAAAA,EANPD,OAMOC,EAAAA;EAIHE;;;AAhBwD;AA4E3E;EAEeE,eAAAA,CAAAA,EAlEOJ,mBAkEPI;EACOJ;;;EAOCS,aAAAA,EAtEJP,cAsEIO;EAIkDE;;;EAA0BC,gBAAAA,CAAAA,EAAAA,MAAAA;EAMhFR;;;;;EAEsCQ,MAAAA,CAAAA,EAAAA,MAAAA;EAtBNhB;;AAA8D;EAwBhGiB,MAAAA,CAAAA,EAAAA,MAAAA;EAAsET;;;EAUxCG,cAAAA,CAAAA,EA5E1BN,cA4E0BM;EAYzBP;;;EAtBgE,gBAAA,CAAA,EAAA,OAAA;AAqDtF;;;;;;;;;;;;;;;;;;;;;;;AAAmN;;;;;;;;;;;;;;cA7E9LU,qBAAAA,SAA8Bd,wBAAAA,YAAoCa;;aAExEL;oBACOJ;iBACHE;;;;kBAICD;;qBAEGQ;;;;yDAIoCJ,cAAcM,0BAA0BC,QAAQF;;;;;;iBAMxFN,cAAcQ;eAChBT;2BACYA,4BAA4BS,QAAQF;;UAEhDG,qCAAAA,SAA8ChB,wBAAwBO;;;;;;aAMxEL;;;;iBAIIS,4BAA4BD;;;;;;;;;;;;oBAYzBP;;;;;;;;;;;;;;;;;;mBAkBDC;;;;;;;;;;;;;cAaAa,kDAAkDV,qEAAqEG,sBAAAA,YAAkCM;;aAE/JT;oBACOJ;iBACHQ,4BAA4BD;;;;kBAI3BN;;;;sBAIIY;;;;;;;yBAOGf,uBAAuBiB,YAAYH,QAAQN;;;;;;iBAMnDR,uBAAuBiB,YAAYH;;;;;;kBAMlCP,cAAcW,uBAAuBJ,QAAQE,iCAAiCC,UAAUC"}