Skip to content

Prompt ($)

The $ is a JavaScript tagged template that expands the string into the final prompt.

example.genai.mjs
$`You are a helpful assistant.`
👤 user
You are a helpful assistant.

Inline expressions

You can weave expressions in the template using ${...}. Expression can be promises and will be awaited when rendering the final prompt.

example.genai.mjs
$`Today is ${new Date().toDateString()}.`
👤 user
Today is Thu Jun 13 2024.

String templating

The output of the $ can be further processed by running popular jinja or mustache template engines.

$`What is the capital of {{ country }}?`.jinja(env.vars)
$`What is the capital of {{ country }}?`.mustache(env.vars)

Inline prompts

When running an inline prompt, you can use the $ to generate the prompt dynamically but you need to call it on the generation context.

example.genai.mjs
const res = await runPrompt(ctx => {
ctx.$`What is the capital of France?`
})