Class: ChatPromptTemplate
prompts.ChatPromptTemplate
Base class for prompt templates. Exposes a format method that returns a string prompt given a set of input values.
Hierarchy
↳
ChatPromptTemplate
Implements
ChatPromptTemplateInput
Constructors
constructor
• new ChatPromptTemplate(input)
Parameters
| Name | Type |
|---|---|
input | ChatPromptTemplateInput |
Overrides
BaseChatPromptTemplate.constructor
Defined in
langchain/src/prompts/chat.ts:186
Properties
inputVariables
• inputVariables: string[]
A list of variable names the prompt template expects
Implementation of
ChatPromptTemplateInput.inputVariables
Inherited from
BaseChatPromptTemplate.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
ChatPromptTemplateInput.outputParser
Inherited from
BaseChatPromptTemplate.outputParser
Defined in
langchain/src/prompts/base.ts:53
partialVariables
• Optional partialVariables: InputValues
Partial variables
Implementation of
ChatPromptTemplateInput.partialVariables
Inherited from
BaseChatPromptTemplate.partialVariables
Defined in
langchain/src/prompts/base.ts:55
promptMessages
• promptMessages: BaseMessagePromptTemplate[]
Implementation of
ChatPromptTemplateInput.promptMessages
Defined in
langchain/src/prompts/chat.ts:182
validateTemplate
• validateTemplate: boolean = true
Implementation of
ChatPromptTemplateInput.validateTemplate
Defined in
langchain/src/prompts/chat.ts:184
Methods
_getPromptType
▸ _getPromptType(): "chat"
Return the string type key uniquely identifying this class of prompt template.
Returns
"chat"
Overrides
BaseChatPromptTemplate._getPromptType
Defined in
langchain/src/prompts/chat.ts:229
format
▸ format(values): Promise<string>
Format the prompt given the input values.
Example
prompt.format({ foo: "bar" });
Parameters
| Name | Type | Description |
|---|---|---|
values | InputValues | A dictionary of arguments to be passed to the prompt template. |
Returns
Promise<string>
A formatted prompt string.
Inherited from
Defined in
langchain/src/prompts/chat.ts:95
formatMessages
▸ formatMessages(values): Promise<BaseChatMessage[]>
Parameters
| Name | Type |
|---|---|
values | InputValues |
Returns
Promise<BaseChatMessage[]>
Overrides
BaseChatPromptTemplate.formatMessages
Defined in
langchain/src/prompts/chat.ts:233
formatPromptValue
▸ formatPromptValue(values): Promise<BasePromptValue>
Format the prompt given the input values and return a formatted prompt value.
Parameters
| Name | Type |
|---|---|
values | InputValues |
Returns
Promise<BasePromptValue>
A formatted PromptValue.
Inherited from
BaseChatPromptTemplate.formatPromptValue
Defined in
langchain/src/prompts/chat.ts:99
mergePartialAndUserVariables
▸ mergePartialAndUserVariables(userVariables): Promise<InputValues>
Parameters
| Name | Type |
|---|---|
userVariables | InputValues |
Returns
Promise<InputValues>
Inherited from
BaseChatPromptTemplate.mergePartialAndUserVariables
Defined in
langchain/src/prompts/base.ts:69
partial
▸ partial(values): Promise<BasePromptTemplate>
Parameters
| Name | Type |
|---|---|
values | PartialValues |
Returns
Promise<BasePromptTemplate>
Overrides
BaseChatPromptTemplate.partial
Defined in
langchain/src/prompts/chat.ts:265
serialize
▸ serialize(): SerializedChatPromptTemplate
Return a json-like object representing this prompt template.
Returns
Overrides
BaseChatPromptTemplate.serialize
Defined in
langchain/src/prompts/chat.ts:253
deserialize
▸ Static deserialize(data): Promise<BasePromptTemplate>
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
| Name | Type |
|---|---|
data | SerializedBasePromptTemplate |
Returns
Promise<BasePromptTemplate>
Inherited from
BaseChatPromptTemplate.deserialize
Defined in
langchain/src/prompts/base.ts:125
fromPromptMessages
▸ Static fromPromptMessages(promptMessages): ChatPromptTemplate
Parameters
| Name | Type |
|---|---|
promptMessages | BaseMessagePromptTemplate[] |
Returns
Defined in
langchain/src/prompts/chat.ts:279