Skip to main content

Namespace: MistralInstructPrompt

Functions

chat

chat(): TextGenerationPromptTemplate<ChatPrompt, string>

Formats a chat prompt as a Mistral instruct prompt.

Note that Mistral does not support system prompts. We emulate them.

Mistral prompt template when system prompt is set:

<s>[INST] ${ system prompt } [/INST] </s> [INST] ${ user msg 1 } [/INST] ${ model response 1 } [INST] ${ user msg 2 } [/INST] ${ model response 2 } [INST] ${ user msg 3 } [/INST]

Mistral prompt template when there is no system prompt:

<s>[INST] ${ user msg 1 } [/INST] ${ model response 1 } </s>[INST] ${ user msg 2 } [/INST] ${ model response 2 } [INST] ${ user msg 3 } [/INST]

Returns

TextGenerationPromptTemplate<ChatPrompt, string>

See

https://docs.mistral.ai/models/#chat-template

Defined in

packages/modelfusion/src/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.ts:88


instruction

instruction(): TextGenerationPromptTemplate<InstructionPrompt, string>

Formats an instruction prompt as a Mistral instruct prompt.

Note that Mistral does not support system prompts. We emulate them.

Mistral prompt template when system prompt is set:

<s>[INST] ${ system prompt } [/INST] </s>[INST] ${instruction} [/INST] ${ response prefix }

Mistral prompt template when there is no system prompt:

<s>[INST] ${ instruction } [/INST] ${ response prefix }

Returns

TextGenerationPromptTemplate<InstructionPrompt, string>

See

https://docs.mistral.ai/models/#chat-template

Defined in

packages/modelfusion/src/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.ts:47


text

text(): TextGenerationPromptTemplate<string, string>

Formats a text prompt as a Mistral instruct prompt.

Mistral prompt template:

<s>[INST] { instruction } [/INST]

Returns

TextGenerationPromptTemplate<string, string>

See

https://docs.mistral.ai/models/#chat-template

Defined in

packages/modelfusion/src/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.ts:21


validateMistralPrompt

validateMistralPrompt(chatPrompt): void

Checks if a Mistral chat prompt is valid. Throws a ChatPromptValidationError if it's not.

  • The first message of the chat must be a user message.
  • Then it must be alternating between an assistant message and a user message.
  • The last message must always be a user message (when submitting to a model).

The type checking is done at runtime when you submit a chat prompt to a model with a prompt template.

Parameters

NameType
chatPromptChatPrompt

Returns

void

Throws

ChatPromptValidationError

Defined in

packages/modelfusion/src/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.ts:154