Your first GenAI script
GenAIScript use stylized JavaScript with minimal syntax.
They are stored as files (genaisrc/*.genai.js
) in your project.
The execution of a genaiscript creates the prompt that will be sent to the LLM.
Use the
> GenAiScript: Create new script...
command in the command palette (Ctrl+Shift+P
on Windows/Linux,⇧⌘P
on Mac) to create a new script.Run the cli
script create
command with the name of the script you want to create.The resulting file will be placed in the
genaisrc
folder in your project.- …
Directorygenaisrc scripts are created here by default
- genaiscript.d.ts (TypeScript type definitions)
- jsconfig.json (TypeScript compiler configuration)
- proofreader.genai.js
- …
- …
the Context
GenAIScript exposes the context through the env
variable. The context is implicitly defined by the location you start executing the script.
- you can right click on a folder and the
env.files
will contain all the files nested in that folder. - you can right click on or in a file and the
env.files
will contain only that file. - you can run the script using the command line interface and specify content of
env.files
in the CLI arguments.
The def
function inlines the content of env.files
in the final prompt in a LLM friendly way. It also has a number of additional options to control precisely how the content should be inlined.
the Task
The $
function is used to build the prompt text, it renders and writes the text to the prompt
($
is a template literal).
$
supports placeholders, ${...}
. You also can reference
the LLM variable defined with def
freely in the text as well.
the Metadata
You can add a call to the script
function to provides metadata about the script
and the model. The metadata is used to display the script in the UI and configure the LLM model.
The title
, description
, and group
properties are used to display the script in the UI
and can be helpful when the user is searching for a script.
Next steps
Run your script from Visual Studio Code.