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

@pipr/core

v0.1.2

Published

PIPR is a library that helps you generate conversational AI prompts with ease. Pipr can be used to generate natural language responses to specific prompts by calling the OpenAI GPT-3 API. Pipr is designed to give better DX on writing prompt functions

Downloads

2

Readme

PIPR - Prepare Input to Prompt and Resolve

PIPR is a library that helps you generate conversational AI prompts with ease. Pipr can be used to generate natural language responses to specific prompts by calling the OpenAI GPT-3 API. Pipr is designed to give better DX on writing prompt functions

Installation

Install pipr using npm or yarn:

npm install @pipr/core
yarn add @pipr/core

Usage

Here is an example usage of Pipr:

const getAge = createPipr()
  .input(
    z.object({
      name: z.string(),
      age: z.number(),
    })
  )
  .prepare(({ age }) => {
    return {
      ...input,
      age: age + 1,
    };
  })
  .prompt({
    system: 'You will remember everythin I say',
    user: ({ name }) => `The age of ${input.name} is:`,
  })
  .history(({ input }) => [
    {
      user: `John is ${input.age - 1} years old`,
      assistant: 'Nice to meet you, John!',
    },
    { user: `Alice is ${input.age + 1} years.`, assistant: 'Hello Alice!' },
  ])
  .resolve(ctx => {
    return ctx.blocks[0].content;
  });

const age = await getAge({ name: 'Alice', age: 44 });
console.log(age); // 46

.input

The .input method sets the schema for the input data. The schema should be defined using the zod library. The method returns a prompter instance that can be used to set the prompt configuration.

pipr.input(z.object({ name: z.string(), age: z.number() }));

.prepare

The .prepare method sets a preparer function that will be called before the prompt is generated. The preparer function takes the raw input data as a parameter and returns a prepared input data that will be used to generate the prompt. This method can be used to fetch async data needed to add to the prompt.

pipr.input(schema).prepare(async rawInput => {
  return {
    name: rawInput.name.toUpperCase(),
    age: rawInput.age * 2,
  };
});

.prompt

The .prompt method sets the prompt configuration. The configuration is an object with user and system properties that represent the user's input and the AI's response, respectively. The properties can be set to a string or a function that returns a string.

pipr.input(schema).prompt({
  user: 'What is your name?',
  system: "You're best greater",
});

.history

The .history method sets a function that will be called to generate a history for the prompt. The function takes a promptify and input as a parameter and should return an array of prompt examples. Prompt examples are objects with a user and an assistant property that represent the user's input and the AI's response, respectively.

pipr
  .input(schema)
  .prompt({
    system: 'Hi there! What can I do for you today?',
    user: ({ name }) => `My name is ${name}. What is your name?`,
  })
  .history(async ({ promptify, prepare }) => {
    const prepared = await prepare({
      name: 'John',
      age: 30,
    });

    return [
      {
        user: promptify(prepared).user, // My name is John. What is your name?
        assistant: 'Hello John! My name is ChatGPT. How can I help you today?',
      },
    ];
  });

.resolve

The .resolve method is called after the request is sent to the Open AI API. It takes the OpenAI API responded and resolves the value to return.