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

unitprompt

v0.0.9

Published

A custom Jest matcher that helps you test prompts

Downloads

42

Readme

unitprompt - Jest

unitprompt is a Jest extension that provides custom matchers for unit testing LLM processes. This library helps ensure that your large language model (LLM) outputs are validated correctly in your tests.

Installation

With npm:

npm install --save-dev unitprompt

With yarn:

yarn add -D unitprompt

Setup

Create a setup script with the following:

setup.js

// add all unitprompt matchers
import { unitPromptMatchers } from './unitPromptMatchers';
expect.extend(unitPromptMatchers);

// or just add specific matchers
import { toBeConciseAnswerTo } from 'unitprompt';
expect.extend({ toBeConciseAnswerTo });

Add your setup script to your Jest setupFilesAfterEnv configuration.

package.json

"jest": {
  "setupFilesAfterEnv": ["./setup.js"]
}

For some features that require LLM calls, please install the dev-dependencies of the packages as well and set the environment variable sh OPENAI_API_KEY

Examples

// easily test whether custom conditions are fulfilled
test("fulfills", async () => {
    await expect("3").toFulfill("What is 1+2?")
})
// test parsability
test('is parsable JSON', () => {
  expect('{"key": "value"}').toBeParsableJson();
  expect('{key: "value"}').not.toBeParsableJson(); // malformed JSON
});
// test the style of an answer
test('should be concise answer', async () => {
    await expect('7').toBeConciseAnswerTo("3+4=?");
    await expect(`
            First of all, you need to learn about the concept of sums. A sum is the result of adding two numbers together.
            This can be done in a variety of ways. There is the traditional method of writing the numbers one on top of the other and adding them together.

            In this instance you can take the first number, 3, and write it down. Then you can take the second number, 4, and write it down below the first number. You can then add the two numbers together to get the sum of 7.
        `).not.toBeConciseAnswerTo("3+4=?");
})