Skip to content
GenAIScript logo A yellow square with genai text

Generative AI Scripting

extract-data.genai.js
// define the context
def("FILE", env.files, { endsWith: ".pdf" })
// structure the data
const schema = defSchema("DATA",
{ type: "array", items: { type: "string" } })
// assign the task
$`Analyze FILE and extract data to JSON
using the ${schema} schema.`

Next steps

Configure your LLMs

Configure the secrets to access your LLMs.

Write your first script

Follow Getting Started to write your first script.

A screenshot of VSCode with a genaiscript opened

Features

GenAIScript brings essential LLM prompt tooling into a cohesive scripting environment.

Stylized Javascript

Build prompts programmatically using JavaScript.

def("FILE", env.files, { endsWith: ".pdf" })
$`Summarize FILE. Today is ${new Date()}.`

Reuse and Share Scripts

Scripts are files! They can be versioned, shared, forked, …

  • Directorygenaisrc
    • my-script.genai.js
    • another-great-script.genai.js

Data Schemas

Define, validate, repair data using schemas.

const data = defSchema("MY_DATA",
{ type: "array", items: { ... }, })
$`Extract data from files using ${data} schema.`

Ingest PDFs, DOCX, CSV, ..

Seamlessly ingest and manipulate PDFs, DOCX, CSV, …

const { pages } = await parsers.PDF(env.files[0])

RAG built-in

Vector search powered by LLamaIndex.

// embedding vector index and search
const { files } = await retrieval.search("cats", env.files)

Automate

Automate using the CLI, integrate reports in your CI/CD pipeline.

npx genaiscript run tlaplus-linter "*.tla"
The image shows a screenshot of a GitHub pull request page. The pull request is titled "Update EDW998PCal.tla #1" and is from a branch named "lemmy-patch-1" into the "master" branch. A bot identified as "github-advanced-security" has flagged potential problems 25 minutes ago. Below, part of a file is shown with a diff view highlighting changes between two versions. Two lines have been altered, where an "ASSUME" statement's comment has been updated from "At least one node" to "Any number of nodes between zero and infinitely many." There's an alert from the TLA+ Linter indicating that the comment is consistent with the TLA+ declaration `N \in Nat \ {0}` which means N is a natural number excluding zero.

Below this, there is a dismissible alert box titled "Check notice" with a "Dismiss alert" button. At the bottom of the screenshot, there's a note that "Some checks were not successful," indicating 1 successful check and 1 failing check. The successful check is by "TLA-linter / TLA-linter (pull_request)" and the failing check is "Code scanning results / genaiscript." There's also a reference to a commit push action to the "master" branch from another branch and a prompt suggesting to add more commits by pushing to the "lemmy-patch-1" branch on "lemmy/Examples".

LLM Composition

Run LLMs to build your LLM prompts.

// 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.`