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

@flowprompter/jest

v0.0.10

Published

Prompt engineering toolkit for Jest

Downloads

12

Readme

About Flow Prompter

Testing and developing prompts has traditionally been tricky because the output a typical LLM creates is fuzzy and non deterministic but with Floe Prompter you can simply manage test regressions using Jest without worrying about output variants that throw your tests off. This works because Flow Prompter delivers a set of Jest matchers that use embeddings to test for semantic similarities between strings. With these matchers, you can easily test if two strings are similar in meaning or compare the similarity of your prompt outputs.

await expect("What a fine day!").toBeMoreSimilarTo(
  "This weather is simply delightful.",
  "It is a fine but weathered day bed."
);

Getting Started

You can install this package using your favourite npm client:

| Client | Command | |---|---| | npm | npm install --save-dev @flowprompter/jest | | pnpm | pnpm add -D @flowprompter/jest | | yarn | yarn add -D @flowprompter/jest |

To use these matchers, simply import the setupMatchers function and pass the output to expect.extend in your setup file or before your tests. Then simply use them with Jest's built-in expect function.

import {setupMatchers} from "@flowprompter/jest"; 

// Setup your matchers before your tests run
expect.extend(setupMatchers({
  openAiApiKey: 'sk-abc123def456...987xyz'
}));

Usage

describe('String similarity tests', () => {
  test('Hello -> Hi', async () => {
    await expect('Hello').toBeSimilarTo('Hi');
  });

  test('Hello -> Yellow', async () => {
    await expect('Hello').toBeSimilarTo('Yellow', 0.8);
  });

  test('Hello is more similar to Hi than Whistle or Lion', async () => {
    await expect('Hello').toBeMoreSimilarTo('Hi', ['Whistle', 'Lion']);
  });
});

API Reference

toBeMoreSimilarTo(expected: string, others: string[] | string)

Checks if the tested string is more similar in meaning to the expected string than it is to any of the other strings provided. The others parameter can be a single string or an array of strings.

Example:

test('Hello is more similar to Hi than Whistle or Lion', async () => {
  await expect('Hello').toBeMoreSimilarTo('Hi', ['Whistle', 'Lion']);
});

toBeSimilarTo(expected: string, threshold?: number)

Checks if the tested string is similar in meaning to the expected string. The optional threshold parameter sets the minimum similarity score required for the test to pass (default is 0.85).

Example:

test('Hello -> Hi', async () => {
  await expect('Hello').toBeSimilarTo('Hi');
});

Caching

All embedding calls are only made once to save tokens and are cached to a file: ~/.config/flowprompter/.fpjembeddings. On windows this file will be something like C:\Users\{username}\AppData\Local\flowprompter\.fpjembeddings.

To configure the file location use the embeddingCachePath option:

import {setupMatchers} from "@flowprompter/jest"; 

// Setup your matchers before your tests run
expect.extend(setupMatchers({
  // other config...
  embeddingCachePath: "/path/to/my/embeddings/cache"
}));

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository. If you'd like to contribute code, please fork the repository and submit a pull request.

  1. Clone this repository
  2. Install dependencies pnpm install
  3. Copy .env.example to .env file and supply your OPENAI_API_KEY
  4. Run tests by pnpm test

Authors