npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

genaiscript

v1.86.4

Published

A CLI for GenAIScript, a generative AI scripting framework.

Downloads

7,591

Readme

A yellow square with the word "gen" in lowercase black letters above the uppercase black letters "AI."

GenAIScript

🚀 JavaScript-ish environment with convenient tooling for file ingestion, prompt development, and structured data extraction.

https://github.com/user-attachments/assets/ce181cc0-47d5-41cd-bc03-f220407d4dd0


🌟 Introduction

Prompting is Coding

Programmatically assemble prompts for LLMs using JavaScript. Orchestrate LLMs, tools, and data in code.

  • JavaScript toolbox to work with prompts
  • Abstraction to make it easy and productive
  • Seamless Visual Studio Code integration

Hello world

Say to you want to create an LLM script that generates a 'hello world' poem. You can write the following script:

$`Write a 'hello world' poem.`

The $ function is a template tag that creates a prompt. The prompt is then sent to the LLM (you configured), which generates the poem.

Let's make it more interesting by adding files, data and structured output. Say you want to include a file in the prompt, and then save the output in a file. You can write the following script:

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

The def function includes the content of the file, and optimizes it if necessary for the target LLM. GenAIScript script also parses the LLM output and will extract the data.json file automatically.


🚀 Quickstart Guide

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

npm install -g genaiscript

✨ 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]+/, { globs: "*.md" })

LLM Tools

Register JavaScript functions as tools (with fallback for models that don't support tools). Model Context Protocol (MCP) tools are also supported.

defTool(
    "weather",
    "query a weather web api",
    { location: "string" },
    async (args) =>
        await fetch(`https://weather.api.api/?location=${args.location}`)
)

LLM Agents

Register JavaScript functions as tools and combine tools + prompt into agents.

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" })

$`Do a statistical analysis of the last commits`

🔍 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 or API

Automate using the CLI or API.

npx genaiscript run tlaplus-linter "*.tla"
import { run } from "genaiscript/api"

const res = await run("tlaplus-linter", "*.tla")

Safety First!

GenAIScript provides built-in Responsible AI system prompts and Azure Content Safety supports to validate content safety.

script({ ...,
    system: ["system.safety_harmful_content", ...],
    contentSafety: "azure" // use azure content safety
})

const safety = await host.contentSafety()
const res = await safety.detectPromptInjection(env.vars.input)

💬 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.",
}})

LLM friendly docs

If you are an LLM crawler, fetch https://microsoft.github.io/genaiscript/.well-known/llms.txt for an documentation map or add the .md suffix to any documentation URLs to get a raw markdown content.

For example, https://microsoft.github.io/genaiscript/guides/prompt-as-code.md (note the .md extension)

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.