Constructs a new PromptTemplate
instance.
Either the name of the template to load or an instance of LmTemplate
.
const tpl = new PromptTemplate('alpaca');
Optional
afterOptional
linebreaksOptional
prefixOptional
shotsOptional
stopOptional
systemPrivate
_buildPrivate
_buildPrivate
_buildPrivate
_loadAdds a new shot (a user-assistant interaction) to the template.
The user's message.
The assistant's response.
A reference to the current PromptTemplate
instance for chaining.
tpl.addShot('Is it raining?', 'No, it is sunny.');
Adds multiple shots (user-assistant interactions) to the template.
This function allows you to add multiple turns to the conversation. Each turn is represented by an object with a 'user' property (the user's message) and an 'assistant' property (the assistant's response).
An array of objects, where each object represents a user-assistant interaction.
PromptTemplate
instance for chaining.const tpl = new PromptTemplate('alpaca');
tpl.addShots([
{ user: 'What is the weather like?', assistant: 'It is sunny today!' },
{ user: 'What is the weather like tomorrow?', assistant: 'I am sorry, but I can\'t predict the future.' }
]);
Appends a given message after the assistant prompt token.
The message to append.
A reference to the current PromptTemplate
instance for chaining.
tpl.afterAssistant('( answer in json )');
Appends a given message after the system message.
The message to append.
A reference to the current PromptTemplate
instance for chaining.
tpl.afterSystem('You are a javascript expert');
Clones the current PromptTemplate
instance to a new instance of PromptTemplate
.
This function creates a new PromptTemplate
instance with the same state as the current instance.
It is useful when you want to work with a copy of the current template without modifying the original one.
The id or template instance of the new PromptTemplate
to make
Keep the shots for the template instance: this will also clone the shots
PromptTemplate
instance with the same state as the current one.const tpl = new PromptTemplate('alpaca');
const clonedTpl = tpl.cloneTo('chatml');
console.log(clonedTpl);
Renders the template with the provided message replacing the {prompt}
placeholder.
The message to use for replacing the {prompt}
placeholder.
The rendered template with the provided message.
const prompted = tpl.prompt("list the planets in the solar system");
console.log(prompted);
Push a turn into history
the history turn
Render a turn block
the shot to render
ther rendered text
Replaces the {prompt}
placeholder in the user message with a given message.
The message to replace the placeholder with.
A reference to the current PromptTemplate
instance for chaining.
tpl.replacePrompt(fix this invalid json:\n\njson\n{prompt}\n
);
Replaces the system block with a given message.
The message to replace the system block with.
A reference to the current PromptTemplate
instance for chaining.
tpl.replaceSystem('You are a javascript expert');
Converts the current PromptTemplate
instance to a JSON object.
This function serializes the current state of the PromptTemplate
instance into a JSON object,
which can be used for storing the template or transmitting it over a network.
PromptTemplate
.const tpl = new PromptTemplate('alpaca');
const json = tpl.toJson();
console.log(json);
Generated using TypeDoc
Represents a modified language model template.
Example