Variables
The env.vars
object contains a set of variable values. You can use these variables to parameterize your script.
// grab locale from variable or default to en-USconst locale = env.vars.locale || "en-US"// conditionally modify promptif (env.vars.explain) $`Explain your reasoning`
Script parameters
It is possible to declare parameters in the script
function call. The env.vars
object will contain the values of these parameters.
script({ parameters: { string: "the default value", // a string parameter with a default value number: 42, // a number parameter with a default value boolean: true, // a boolean parameter with a default value stringWithDescription: { // a string parameter with a description type: "string", default: "the default value", description: "A description of the parameter", }, },})
When invoking this script in VS Code, the user will be prompted to provide values for these parameters.
Variables from the CLI
Use the vars
field in the CLI to override variables. vars takes a sequence of key=value
pairs.
npx genaiscript run ... --vars myvar=myvalue myvar2=myvalue2 ...
Variables in tests
You can specify variables in the tests
object of the script
function. These variables will be available in the test scope.
script({ ..., tests: { ..., vars: { number: 42 } }})