提示词 ($)
$
是一个JavaScripttagged template,它将字符串扩展为最终的提示词。
$`You are a helpful assistant.`
👤 user
You are a helpful assistant.
内联表达式
您可以在模板中使用${...}
来嵌入表达式。这些表达式可以是Promise对象,在渲染最终提示时会被自动等待解析。
$`Today is ${new Date().toDateString()}.`
👤 user
Today is Thu Jun 13 2024.
字符串模板
$
的输出可以通过运行流行的jinja或mustache模板引擎进一步处理。
$`What is the capital of {{ country }}?`.jinja(env.vars)
$`What is the capital of {{ country }}?`.mustache(env.vars)
内联提示
当运行inline prompt时,您可以使用$
动态生成提示,但需要在生成上下文中调用它。
const res = await runPrompt(ctx => { ctx.$`What is the capital of France?`})