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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@botpress/vai

v0.0.5

Published

Vitest AI (vai) – a vitest extension for testing with LLMs

Downloads

1,099

Readme

Vitest AI

Vai (stands for Vitest + AI) is a lightweight vitest extension that uses LLMs to do assertions. The goal of this library is primarily to allow testing the output of LLMs like the new autonomous engine, as the output is dynamic and qualitative we can't rely on traditional hard-coded tests.

To remove the flakiness and human-input from these tests, we need LLMs.

It's built on top of Zui and the Botpress client to interface with the different LLMs.

Usage

import { check, rate, filter, extract } from '@botpress/vai'
import { describe, test } from 'vitest'

describe('my test suite', () => {
  test('example', () => {
    check('botpress', 'is a chatbot company').toBe(true)
  })
})

check (assertion)

Checks that the provided value matches the provided condition

test('example', () => {
  // works with strings
  check('hello', 'is a greeting message').toBe(true)

  // also works with objects, arrays etc..
  check(
    {
      message: 'hello my friend',
      from: 'user'
    },
    'is a greeting message'
  ).toBe(true)
})

extract (assertion)

Extracts from anything in input the requested Zui Schema:

const person = z.object({
  name: z.string(),
  age: z.number().optional(),
  country: z.string().optional()
})

extract('My name is Sylvain, I am 33 yo and live in Canada', person).toMatchObject({
  name: 'Sylvain',
  age: 33,
  country: 'Canada'
})

Also added support for toMatchInlineSnapshot:

test('toMatchInlineSnapshot', () => {
  extract('My name is Eric!', z.object({ name: z.string() })).toMatchInlineSnapshot(`
    {
      "name": "Eric",
    }
  `)
})

filter (assertion)

Filters an array of anything T[] based on a provided condition:

const countries = ['canada', 'germany', 'usa', 'paris', 'mexico']
filter(countries, 'is in north america').toBe(['canada', 'usa', 'mexico'])
filter(countries, 'is the name of a country').length.toBe(4)

rate (assertion)

Given any input T, gives a rating between 1 (worst) and 5 (best):

test('good', () => rate('ghandi', 'is a good person').toBeGreaterThanOrEqual(4))
test('evil', () => rate('hitler', 'is a good person').toBe(3))

Few-shot Examples

All assertion methods accept examples to provide the LLM with few-shot learning and help increase the accuracy.

describe('learns from examples', () => {
  test('examples are used to understand how to classify correctly', () => {
    const examples = [
      {
        expected: true,
        value: 'Rasa the chatbot framework',
        reason: 'Rasa is a chatbot framework, so it competes with Botpress'
      },
      {
        expected: false,
        value: 'Rasa the coffee company',
        reason: 'Since Rasa is a coffee company, it does not compete with Botpress which is not in the coffee business'
      }
    ]

    check('Voiceflow', 'is competitor', { examples }).toBe(true)
    check('Toyota', 'is competitor', { examples }).toBe(false)
  })
})

Failure Messages

All model predictions have nice failure messages by default:

const countries = ['canada', 'germany', 'usa', 'paris', 'mexico']
filter(countries, 'is in north america').toBe(['canada', 'usa'])

Promises

All assertion methods can also be used outside Vitest tests, as they return an PromiseLike<T> object that can be awaited.

test('test truth', async () => {
  const { result } = await check('hello', 'is a greeting message')
  expect(result).toBe(true)
})

Bail on failure

You can await the assertion to bail immediately on failure and prevent other test cases to run:

test('no bail', () => {
  check('hello', 'is a greeting message').toBe(false)
  console.log('this will run as the above is not awaited, it will bail at the end of the test')
})

test('bail', async () => {
  await check('hello', 'is a greeting message').toBe(false)
  console.log('this will not run, the test has bailed')
})

Changing the evaluator model

By default, GPT-4o mini is used to evaluate the tests, but the evaluator can be changed from inside a test:

test('simple', () => {
  setEvaluator('anthropic__claude-3-5-sonnet-20240620')
  rate('hello', 'is a greeting message').toBe(5)
})