Skip to main content

Class: FewShotPromptTemplate

prompts.FewShotPromptTemplate

Prompt template that contains few-shot examples.

Hierarchy

Implements

Constructors

constructor

new FewShotPromptTemplate(input)

Parameters

NameType
inputFewShotPromptTemplateInput

Overrides

BaseStringPromptTemplate.constructor

Defined in

langchain/src/prompts/few_shot.ts:88

Properties

examplePrompt

examplePrompt: PromptTemplate

An PromptTemplate used to format a single example.

Implementation of

FewShotPromptTemplateInput.examplePrompt

Defined in

langchain/src/prompts/few_shot.ts:76


exampleSelector

Optional exampleSelector: BaseExampleSelector

An BaseExampleSelector Examples to format into the prompt. Exactly one of this or examples must be provided.

Implementation of

FewShotPromptTemplateInput.exampleSelector

Defined in

langchain/src/prompts/few_shot.ts:74


exampleSeparator

exampleSeparator: string = "\n\n"

String separator used to join the prefix, the examples, and suffix.

Implementation of

FewShotPromptTemplateInput.exampleSeparator

Defined in

langchain/src/prompts/few_shot.ts:80


examples

Optional examples: InputValues[]

Examples to format into the prompt. Exactly one of this or exampleSelector must be provided.

Implementation of

FewShotPromptTemplateInput.examples

Defined in

langchain/src/prompts/few_shot.ts:72


inputVariables

inputVariables: string[]

A list of variable names the prompt template expects

Implementation of

FewShotPromptTemplateInput.inputVariables

Inherited from

BaseStringPromptTemplate.inputVariables

Defined in

langchain/src/prompts/base.ts:51


outputParser

Optional outputParser: BaseOutputParser

How to parse the output of calling an LLM on this formatted prompt

Implementation of

FewShotPromptTemplateInput.outputParser

Inherited from

BaseStringPromptTemplate.outputParser

Defined in

langchain/src/prompts/base.ts:53


partialVariables

Optional partialVariables: InputValues

Partial variables

Implementation of

FewShotPromptTemplateInput.partialVariables

Inherited from

BaseStringPromptTemplate.partialVariables

Defined in

langchain/src/prompts/base.ts:55


prefix

prefix: string = ""

A prompt template string to put before the examples.

Default Value

""

Implementation of

FewShotPromptTemplateInput.prefix

Defined in

langchain/src/prompts/few_shot.ts:82


suffix

suffix: string = ""

A prompt template string to put after the examples.

Implementation of

FewShotPromptTemplateInput.suffix

Defined in

langchain/src/prompts/few_shot.ts:78


templateFormat

templateFormat: TemplateFormat = "f-string"

The format of the prompt template. Options are: 'f-string', 'jinja-2'

Implementation of

FewShotPromptTemplateInput.templateFormat

Defined in

langchain/src/prompts/few_shot.ts:84


validateTemplate

validateTemplate: boolean = true

Whether or not to try validating the template on initialization.

Implementation of

FewShotPromptTemplateInput.validateTemplate

Defined in

langchain/src/prompts/few_shot.ts:86

Methods

_getPromptType

_getPromptType(): "few_shot"

Return the string type key uniquely identifying this class of prompt template.

Returns

"few_shot"

Overrides

BaseStringPromptTemplate._getPromptType

Defined in

langchain/src/prompts/few_shot.ts:119


format

format(values): Promise<string>

Format the prompt given the input values.

Example

prompt.format({ foo: "bar" });

Parameters

NameTypeDescription
valuesInputValuesA dictionary of arguments to be passed to the prompt template.

Returns

Promise<string>

A formatted prompt string.

Overrides

BaseStringPromptTemplate.format

Defined in

langchain/src/prompts/few_shot.ts:150


formatPromptValue

formatPromptValue(values): Promise<BasePromptValue>

Format the prompt given the input values and return a formatted prompt value.

Parameters

NameType
valuesInputValues

Returns

Promise<BasePromptValue>

A formatted PromptValue.

Inherited from

BaseStringPromptTemplate.formatPromptValue

Defined in

langchain/src/prompts/base.ts:152


mergePartialAndUserVariables

mergePartialAndUserVariables(userVariables): Promise<InputValues>

Parameters

NameType
userVariablesInputValues

Returns

Promise<InputValues>

Inherited from

BaseStringPromptTemplate.mergePartialAndUserVariables

Defined in

langchain/src/prompts/base.ts:69


partial

partial(values): Promise<FewShotPromptTemplate>

Parameters

NameType
valuesPartialValues

Returns

Promise<FewShotPromptTemplate>

Overrides

BaseStringPromptTemplate.partial

Defined in

langchain/src/prompts/few_shot.ts:138


serialize

serialize(): SerializedFewShotTemplate

Return a json-like object representing this prompt template.

Returns

SerializedFewShotTemplate

Overrides

BaseStringPromptTemplate.serialize

Defined in

langchain/src/prompts/few_shot.ts:163


deserialize

Static deserialize(data): Promise<FewShotPromptTemplate>

Load a prompt template from a json-like object describing it.

Remarks

Deserializing needs to be async because templates (e.g. FewShotPromptTemplate) can reference remote resources that we read asynchronously with a web request.

Parameters

NameType
dataSerializedFewShotTemplate

Returns

Promise<FewShotPromptTemplate>

Overrides

BaseStringPromptTemplate.deserialize

Defined in

langchain/src/prompts/few_shot.ts:186