Scripting environment with convenient tooling for file ingestion, prompt development and structured data extraction.
![A screenshot of a code editor with multiple tabs open, showing TypeScript code for a "Code Optimizer" script. The editor displays a script with a class named "Greeter" and a description of optimizing code performance. The right pane previews the script's output and optimization suggestions. The left sidebar contains file navigation and icons for various functions.](https://microsoft.github.io/genaiscript/images/visual-studio-code.png)
Features
- 💵 Prompt programmatically using stylized JavaScript.
// define the context
def("FILE", env.files, { endsWith: ".pdf" })
// define the data
const schema = defSchema("DATA", { type: "array", items: { type: "string" } })
// define the task
$`Analyze FILE and
extract titles to JSON compliant with ${schema}.`
![A screenshot of a Visual Studio Code interface in debug mode, showing a paused breakpoint in a JavaScript file. The left side displays the "WATCH" and "CALL STACK" panels, while the right side shows code involving a filter function and a Python file label.](https://microsoft.github.io/genaiscript/images/vscode-debugger.png)
📁 Scripts are files! They can be versioned, shared, forked, ...
📊 Define, validate, repair data using schemas. Zod support builtin.
const data = defSchema("MY_DATA",
{ type: "array", items: { ... }, })
$`Extract data from files using ${data} schema.`
const { pages } = await parsers.PDF(env.files[0])
// embedding vector index and search
const files = await retrieval.vectorSearch("cats", env.files)
- 🚀 Automate using the CLI.
npx --yes genaiscript run my-script "*.pdf"
// summarize each files individually
for (const file of env.files) {
const { text } = await runPrompt((_) => {
_.def("FILE", file)
_.$`Summarize the FILE.`
})
// use result in main prompt
_.def("SUMMARY", text)
}
// use summary
$`Summarize all the summaries.`
Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
Microsoft's Trademark & Brand Guidelines.
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.