跳至内容

导入模板

各种LLM工具允许将提示存储在文本或Markdown文件中。 您可以使用importTemplate将这些文件导入为提示。

cot.md
Explain your answer step by step.
tool.genai.mjs
importTemplate("cot.md")

变量插值

importTemplate 支持 mustache(默认)、Jinja 变量插值和 Prompty 文件格式。您可以在导入的模板中使用变量,并将它们作为参数传递给 importTemplate 函数。

时间.md
The current time is {{time}}.
tool.genai.mjs
importTemplate("time.md", { time: "12:00" })

Mustache支持将参数作为函数传递。这允许您向模板传递动态值。

tool.genai.mjs
importTemplate("time.md", { time: () => Date.now() })

更多指定文件的方式

你可以使用workspace.readText的结果。

tool.genai.mjs
const file = await workspace.readText("time.md")
importTemplate(time, { time: "12:00" })

您可以指定文件数组或通配符模式。

importTemplate("*.prompt")

Prompty

Prompty 提供了一种基于Markdown的简单提示格式。它在Markdown格式中增加了角色部分的概念。

---
name: Basic Prompt
description: A basic prompt that uses the chat API to answer questions
---
inputs:
question:
type: string
sample:
"question": "Who is the most famous person in the world?"
---
system:
You are an AI assistant who helps people find information.
As the assistant, you answer questions briefly, succinctly.
user:
{{question}}
tool.genai.mjs
importTemplate("basic.prompty", { question: "what is the capital of France?" })