跳至内容

输出构建器

env.output 对象用于为脚本执行构建markdown输出。它提供了添加文本、图像、表格和其他元素到输出的方法。

const { output } = env
output.heading(3, "Analysis report")

来自主脚本的LLM响应也会自动添加到输出中。

const { output } = env
output.heading(3, "A poem...")
$`Write a poem` // piped to output as well

Markdown支持

  • 标题
output.heading(2, "Project Overview")
  • 围栏代码块
output.fence("let x = 0", "js")
  • details 中的围栏代码块
output.detailsFence("code", "let x = 0", "js")
  • 警告、注意、谨慎
output.warn("Probably not a good idea.")
  • image
output.image("https://example.com/image.png", "Sample Image")
  • 表格示例
output.table([
{ Name: "Alice", Role: "Developer" },
{ Name: "Bob", Role: "Designer" },
])
  • 结果项
output.resultItem(true, "All tests passed successfully.")
output.resultItem(false, "There were errors in the deployment process.")
  • 详情
output.startDetails("Deployment Details", { success: true, expanded: true })
output.appendContent("Deployment completed on 2024-04-27.")
output.endDetails()

OutputBuilder 接口中还有更多可用的函数。

cli

您可以使用run命令中的--out-output标志来指定输出文件的保存位置。

终端窗口
genaiscript run ... --out-output ./output.md