GenAIScript: Automatable GenAI Scripting with TypeScript/JavaScript

Summary
GenAIScript is an open-source project from Microsoft that enables programmatic assembly of prompts for Large Language Models (LLMs) using JavaScript and TypeScript. It allows developers to orchestrate LLMs, tools, and data directly in code, streamlining the development of GenAI applications. This framework offers seamless Visual Studio Code integration and a flexible command-line interface for efficient GenAI scripting.
Repository Info
Tags
Click on any tag to explore related repositories
Introduction
GenAIScript is a powerful open-source project from Microsoft designed to simplify and automate the process of interacting with Large Language Models (LLMs). Its core philosophy, "Prompting is Coding," allows developers to programmatically assemble prompts, orchestrate LLMs, integrate tools, and manage data using familiar JavaScript and TypeScript. This framework aims to make GenAI development more productive and manageable, offering a robust environment for building intelligent applications.
Installation
Getting started with GenAIScript is straightforward. You can quickly set up your development environment by installing the Visual Studio Code Extension or using the command-line interface.
For detailed instructions, refer to the official documentation:
Examples
Hello World Poem
This simple script demonstrates how to send a prompt to an LLM using the $ template tag.
$`Write a 'hello world' poem.`
Including Files and Structured Output
GenAIScript allows you to easily include file content in your prompts and automatically parse LLM output for structured data like JSON.
// read files
const file = await workspace.readText("data.txt")
// include the file content in the prompt in a context-friendly way
def("DATA", file)
// the task
$`Analyze DATA and extract data in JSON in data.json.`
LLM Agents
Define and use agents that combine tools and prompts for complex tasks.
defAgent(
"git",
"Query a repository using Git to accomplish tasks.",
`Your are a helpful LLM agent that can use the git tools to query the current repository.
Answer the question in QUERY.
- The current repository is the same as github repository.`,
{ model, system: ["system.github_info"], tools: ["git"] }
)
Then use it as a tool:
script({ tools: "agent_git" })
$`Do a statistical analysis of the last commits`
RAG Built-in
Leverage Retrieval Augmented Generation (RAG) with built-in vector search capabilities.
const { files } = await retrieval.vectorSearch("cats", "**/*.md")
Why Use GenAIScript
- Programmatic Prompting: Build prompts dynamically using familiar JavaScript and TypeScript, enabling complex logic and data integration.
- Fast Development Loop: Enjoy a streamlined workflow with integrated debugging, running, and testing capabilities within Visual Studio Code or via the command line.
- Extensive Integrations: Supports various LLM providers including GitHub Copilot, OpenAI, Azure OpenAI, Anthropic, and local models via Ollama or LocalAI.
- Rich Data Handling: Easily ingest and manipulate data from PDFs, DOCX, CSV, XLSX, define data schemas for validation, and generate files from LLM outputs.
- Advanced Features: Includes support for LLM tools, agents, RAG, code interpreters, containers, video processing, LLM composition, and Prompty files.
- Safety and Reliability: Features built-in Responsible AI system prompts, Azure Content Safety support, and robust testing/evaluation tools powered by promptfoo.
- Automation: Automate GenAI workflows with a powerful CLI and API, including integration into Pull Request reviews.