跳至内容

运行脚本

Visual Studio Code

在Visual Studio Code中,您开始运行脚本的位置决定了env.files变量中的条目。

单个文件

  • 在资源管理器中右键点击文件并选择运行GenAIScript…
  • 或者在文件编辑器中右键点击并选择运行 GenAIScript…

env.files 数组将包含一个元素,即所选文件。

A file explorer window shows various files and folders. The file "Document.docx" is selected, and a context menu is open with the option "Run GenAIScript..." highlighted.

文件夹

  • 在资源管理器中右键点击文件夹并选择运行GenAIScript…

env.files 数组将包含该文件夹下的所有嵌套文件。

The image shows a file explorer with a context menu. The "rag" folder is expanded, displaying files like "Document.docx." The context menu includes options like "New File," "Cut," "Copy," and "Run GenAIScript."

GitHub Copilot Chat

您可以通过@genaiscript参与者在GitHub Copilot Chat中运行脚本。

A screenshot of the chat participant window.

默认文件

您可以指定默认文件或文件来运行脚本。 当您从脚本文件本身运行脚本,或使用不带文件参数的命令行时, 将使用默认文件。

script({
files: "path/to/files*.md",
})
...

任务

GenAIScript扩展会自动将每个脚本暴露为一个Task

该任务启动cli并运行所选脚本,同时将当前打开编辑器的路径传递给它。

  • 打开命令面板 Ctrl+Shift+P 并搜索“Tasks: Run Task”
  • 选择 genaiscript 任务提供程序
  • 选择您想要运行的脚本

分析结果

默认情况下,GenAIScript会打开输出预览窗口,显示LLM输出的渲染视图(假设LLM生成的是markdown格式内容)。

GenAIScript视图提供了最新运行轨迹的概览。

您也可以使用Trace来查看脚本执行过程中每个转换步骤。

  • 点击GenAIScript状态栏图标可查看各种选项来调查结果。

A code editor displaying a JSON array with city data, including names, populations, and Wikipedia URLs. A toolbar at the top shows options like "Retry," "Output," and "Trace." The bottom right corner indicates "150 tokens."

命令行

首先通过命令行创建一个脚本。

  • JavaScript
终端窗口
npx genaiscript scripts create proofreader
  • TypeScript “—typescript”
终端窗口
npx genaiscript scripts create proofreader --typescript

scripts create 命令还会生成一个 TypeScript 定义文件 (genaiscript.d.tstsconfig.json),以便在编辑器中启用类型检查和自动补全功能。如果需要重新生成 TypeScript 定义文件,请使用 scripts fix 命令。

终端窗口
npx genaiscript scripts fix

使用run命令从命令行执行脚本。

终端窗口
npx genaiscript run proofreader path/to/files*.md

您可以启动一个playground,通过类似于Visual Studio Code扩展的网页界面交互式地运行脚本。

终端窗口
npx genaiscript serve

下一步

Debug 使用Visual Studio Code调试器调试你的脚本!