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

jipiscript

v1.1.1

Published

OpenAI GPT functions made easy

Downloads

19

Readme

Jipiscript

Jipiscript has changed... just a bit.

Jipiscript is a JavaScript library that allows you ~~to integrate OpenAI's GPT-3 language model into your projects.~~ ~~It allows you to ask questions using natural language and parameters and receive answers or results in a variety of data formats without ever generating any code.~~ ... Well actually... it kind of still does that, but it also does much more!

TL;DR What is it? What does it do?

With Jipiscript, you can:

  • Send a parametrized prompt, specify the type of the answer! (string, number, array, object, custom class instance... sky isn't even a limit)
const imdb = (series) => jipi.ask("get imdb details of $series", { series }, {
  title: j.string(),
  rating: j.number(),
  cast: [{ lastname: j.string(), superHeroName: j.string("wordPlay on his/her last name")}],
});

console.log(await imdb("Black Adder"));
{
    title: 'Black Adder',
    rating: 8.1,
    cast: [
        { lastname: 'Atkinson', superHeroName: 'Atkinstorm' },
        { lastname: 'Robinson', superHeroName: 'Robinsman' },
        { lastname: 'Laurie', superHeroName: 'Doctor Laurie' },
        { lastname: 'Fry', superHeroName: 'Fry Fighter' }
    ]
}
  • Make GPT execute a function
    // This line will create a jipified function that will add a button to the body of the document
    // The function is still usable as a normal function
    const addButton = jipify(
        /**function**/({ text, color }) => {
            const button = document.createElement('button');
            button.innerText = text;
            button.style.backgroundColor = color;
            document.body.appendChild(button);
            return button;
        },
        /**parameters description**/{
            text: j.string("text to display on the button"),
            color: j.string("color of the button in hex format"),
        },
        /**function description**/"add a button to the body of the document"
    );

    // This line will add a blue button with the text "Hello" to the body of the document and return the button element
    const helloButton = addButton({ text: "Hello", color: "#0000ff" });
    
    // This line will add a funny button to the body of the document and return the button element
    const funnyButton = await jipi.call("add a funny button for a birthday card", {}, [addButton]);
  • Give a task and a bunch of functions to GPT and let the magic happen
    const functions = [
        jipify(
            function getContactElectronicAddress({ name }) {return `${name}@mail.com`},    //function
            { name: j.string("name of the contact") },                                    //parameters description
            "retrieve contact's electronic address"                                               //function description
        ),
  
        jipify(
          function listContacts() {return ["Guillaume", "Raj", "Jake"];},
          {},
          "list contacts"
        ),
  
        jipify(
          function fakeSendEmail({ address, subject, message }){
              console.log(`Sending email to ${address} with subject ${subject} and message ${message}`);
              return "mail sent";
          },
          {
              address: j.string(),
              subject: j.string(),
              message: j.string(), 
          },
          "send email"
        )
    ];


  await jipi.call("Send a welcome mail to the first 2 contacts", {}, functions);

Installation

Using npm :

npm install --save jipiscript

Initialization

Assuming you already have an OpenAI API key set up as an environment variable:

import { Jipiscript, jipify, j, Gpt4FunctionWrapper } from "jipiscript";

const jipi = new Jipiscript(new Gpt4FunctionWrapper(
  process.env.OPENAI_API_KEY,
  {
    model: "gpt-4-0613",
    temperature: 0.7,
    max_tokens: 2049,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
  }
));

Basic usage

  • Simple example to retrieve an array of objects:
const getCapitals = (countries) => jipi.ask("What are the capital of $countries?", { countries }, [{ name: String, inhabitants: Number}]);

console.log(await getCapitals(["France", "Belgium", "Canada"]));
/*[
    { name: 'Paris', inhabitants: 2148327 },
    { name: 'Brussels', inhabitants: 1211035 },
    { name: 'Ottawa', inhabitants: 934243 }
]*/
const Person = jipify(
  class {
    constructor({name, birthYear}) {
      this.name = name;
      this.birthYear = birthYear;
    }
  },
  { name: j.string(), birthYear: j.number()}
);

// This line create a new Person
const Person1 = new Person({ name: "James", birthYear: 1996 });

// This line will ask GPT-3 to find the first black president of the USA and return it as a Person instance
const Person2 = await jipi.ask("Who's the first black president of the USA?", {}, Person);
console.log(answer); // Person { name: "Barack Obama", birthYear: 1961 }