Skip to content

microsoft/genaiscript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GenAIScript Logo

GenAIScript

πŸš€ JavaScript-ish environment with convenient tooling for file ingestion, prompt development, and structured data extraction.

Read the ONLINE DOCUMENTATION at microsoft.github.io/genaiscript

🌟 Introduction

GenAIScript is a powerful scripting environment tailored for building and managing Large Language Model (LLM) prompts with ease. Whether you are a developer, data scientist, or researcher, GenAIScript provides the tools you need to create, debug, and share scripts efficiently.

πŸ€– This readme is maintained by the readme-updater script.

πŸš€ Quickstart Guide

Get started quickly by installing the Visual Studio Code Extension or using the command line.

✨ Features

🎨 Stylized JavaScript & TypeScript

Build prompts programmatically using JavaScript or TypeScript.

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

πŸš€ Fast Development Loop

Edit, Debug, Run, and Test your scripts in Visual Studio Code or with the command line.

πŸ”— Reuse and Share Scripts

Scripts are files! They can be versioned, shared, and forked.

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

πŸ“‹ Data Schemas

Define, validate, and repair data using schemas.

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

πŸ“„ Ingest Text from PDFs, DOCX, ...

Manipulate PDFs, DOCX, ...

def("PDF", env.files, { endsWith: ".pdf" })
const { pages } = await parsers.PDF(env.files[0])

πŸ“Š Ingest Tables from CSV, XLSX, ...

Manipulate tabular data from CSV, XLSX, ...

def("DATA", env.files, { endsWith: ".csv", sliceHead: 100 })
const rows = await parsers.CSV(env.files[0])
defData("ROWS", rows, { sliceHead: 100 })

πŸ“ Generate Files

Extract files and diff from the LLM output. Preview changes in Refactoring UI.

$`Save the result in poem.txt.`
FILE ./poem.txt
The quick brown fox jumps over the lazy dog.

πŸ” File Search

Grep or fuzz search files.

const { files } = await workspace.grep(/[a-z][a-z0-9]+/, "**/*.md")

πŸ” RAG Built-in

Vector search.

const { files } = await retrieval.vectorSearch("cats", "**/*.md")

πŸ™ GitHub Models and GitHub Copilot

Run models through GitHub Models or GitHub Copilot.

script({ ..., model: "github:gpt-4o" })

πŸ’» Local Models

Run your scripts with Open Source models, like Phi-3, using Ollama, LocalAI.

script({ ..., model: "ollama:phi3" })

🐍 Code Interpreter

Let the LLM run code in a sandboxed execution environment.

script({ tools: ["python_code_interpreter"] })

🐳 Containers

Run code in Docker containers.

const c = await host.container({ image: "python:alpine" })
const res = await c.exec("python --version")

🧩 LLM Composition

Run LLMs to build your LLM prompts.

for (const file of env.files) {
    const { text } = await runPrompt((_) => {
        _.def("FILE", file)
        _.$`Summarize the FILE.`
    })
    def("SUMMARY", text)
}
$`Summarize all the summaries.`

πŸ…ΏοΈ Prompty support

Run your Prompty files as well!

---
name: poem
---

Write me a poem

βš™ Automate with CLI

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

npx genaiscript run tlaplus-linter "*.tla"

πŸ’¬ Pull Request Reviews

Integrate into your Pull Requests checks through comments, reviews, or description updates. Supports GitHub Actions and Azure DevOps pipelines.

npx genaiscript ... --pull-request-reviews

⭐ Tests and Evals

Build reliable prompts using tests and evals powered by promptfoo.

script({ ..., tests: {
  files: "penguins.csv",
  rubric: "is a data analysis report",
  facts: "The data refers about penguin population in Antarctica.",
}})

Contributing

We accept contributions! Checkout the CONTRIBUTING page for details and developer setup.

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.