Prompty
GenAIScript支持将.prompty文件作为脚本运行(存在一些限制)或在脚本中导入它们。
什么是prompty?
Prompty是一种类似markdown的文件格式,用于存储参数化提示词以及模型信息。
---name: Basic Promptdescription: A basic prompt that uses the chat API to answer questionsmodel: api: chat configuration: type: azure_openai azure_deployment: gpt-4o parameters: max_tokens: 128 temperature: 0.2inputs: question: type: stringsample: "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}}
{{hint}}有两种方式可以利用prompty文件与GenAIScript:
- 直接通过GenAIScript运行它们
- 在脚本中使用
importTemplate导入它们
使用GenAIScript运行.prompty文件
你可以从cli或Visual Studio Code中运行.prompty文件,就像运行其他.genai.mjs脚本一样。
GenAIScript会将.prompty内容转换为脚本并执行。它支持大部分前置选项,但主要忽略模型配置部分。
这是basic.prompty文件编译后的结果:
script({ model: "openai:gpt-4o", title: "Basic Prompt", description: "A basic prompt that uses the chat API to answer questions", parameters: { question: { type: "string", default: "Who is the most famous person in the world?", }, }, temperature: 0.2, maxTokens: 128,})
writeText( `You are an AI assistant who helps people find information.As the assistant, you answer questions briefly, succinctly.`, { role: "system" })$`{{question}}
{{hint}}`.jinja(env.vars)导入.prompty文件
你也可以在生成提示时使用importTemplate导入并渲染一个.prompty文件。
importTemplate("basic.prompty", { question: "what is the capital of france?", hint: "starts with p",})在此场景中,.prompty文件不会作为脚本执行,而是作为模板导入。importTemplate函数将使用提供的参数渲染该模板。
支持的功能
name,description,temperature,max_tokens,top_p, …0inputs转换为parameterssample值填充参数default部分outputs转换为responseSchema- Jinja2 模板引擎
限制条件
- 模型配置使用GenAIScript
.env文件(参见configuration)。 - 目前还不支持图片
扩展功能
genaiscript使用的额外字段:
files用于指定一个或多个文件来填充env.filestests用于指定一个或多个测试