Skip to main content

Namespace: Llama2Prompt

Functions

chat

chat(): TextGenerationPromptTemplate<ChatPrompt, string>

Formats a chat prompt as a Llama 2 prompt.

Llama 2 prompt template:

<s>[INST] <<SYS>>
${ system prompt }
<</SYS>>

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

Returns

TextGenerationPromptTemplate<ChatPrompt, string>

Defined in

packages/modelfusion/src/model-function/generate-text/prompt-template/Llama2PromptTemplate.ts:79


instruction

instruction(): TextGenerationPromptTemplate<InstructionPrompt, string>

Formats an instruction prompt as a Llama 2 prompt.

Llama 2 prompt template:

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

Returns

TextGenerationPromptTemplate<InstructionPrompt, string>

See

https://www.philschmid.de/llama-2#how-to-prompt-llama-2-chat

Defined in

packages/modelfusion/src/model-function/generate-text/prompt-template/Llama2PromptTemplate.ts:49


text

text(): TextGenerationPromptTemplate<string, string>

Formats a text prompt as a Llama 2 prompt.

Llama 2 prompt template:

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

Returns

TextGenerationPromptTemplate<string, string>

See

https://www.philschmid.de/llama-2#how-to-prompt-llama-2-chat

Defined in

packages/modelfusion/src/model-function/generate-text/prompt-template/Llama2PromptTemplate.ts:25


validateLlama2Prompt

validateLlama2Prompt(chatPrompt): void

Checks if a Llama2 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/Llama2PromptTemplate.ts:136