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

gptio

v1.0.5

Published

A dead simple langchain implementation for Open AI chat models.

Downloads

3

Readme

GPTIO

NPM Download Stats

A simple typescript alternative to langchain custom tools in a few hundred LOC to buck all the pointless prompt psuedoscience.

Demo Gif


Start by installing:

npm i gptio

Set an environment variable:

OPENAI_API_KEY=sk-***************************

Everything you need to get started:

import GPTIO from "gptio";

// Inputs to "actions" are passed through a single input object
function add({a, b}) {
  return a + b;
}

function multiply({a, b}) {
  return a * b;
}

const gptio = new GPTIO(
  // OpenAI chat model (gpt-3.5-turbo or gpt-4)
  "gpt-4",
  // Actions to give GPTIO (your functions + descriptions)
  [
    {
      name: "add",
      description: "Adds two numbers together.",
      func: add,
      inputs: [
        {
          name: "a",
          type: "number", // Any valid JSON type
          description: "The first number to add.",
        },
        {
          name: "b",
          type: "number",
          description: "The second number to add.",
        },
      ],
    },
    {
      name: "multiply",
      description: "Multiplies two numbers together.",
      func: multiply,
      inputs: [
        {
          name: "a",
          type: "number",
          description: "The first number to multiply.",
        },
        {
          name: "b",
          type: "number",
          description: "The second number to multiply.",
        },
      ],
    }
  ],
  // Optional custom callbacks for progress reporting, custom memory schemes, or early exits
  {
    beforeAction: (action, input) => {
      // Add custom logic that should be run before each action
      // throw an error to interrupt and end the run
    },
    afterAction: (action, input, result) => {
      // ...run after each action is executed
    },
    afterThought: (thought) => {
      // ...run after each thought is generated
    }
  },
  // GPTIO options
  {
    // enable a built-in JS code execution action using safe-eval
    // in smooth brain terms: GPTIO can self-author custom tools
    evaluation: true,
    // print the entire chain of thought at the end
    debug: true,
    // timeout in seconds for the entire run
    timeout: 100
  }
);

gptio.run("Get me the current time and identify if the number of minutes is a prime number.").then((result) => {
  // results look like { result: any, message: string }
  // errors look like { error: true, message: string }
  console.log(result);
}).catch((error) => {
  // execution error (timeout, error thrown from callback, Open AI, etc.)
  console.log(error);
});

GPTIO will reason through and execute actions in a sequence to solve whatever task you give it in run(), and will attempt to inform you if the actions you've provided are insufficient.


Memory

Memory can be easily integrated with GPTIO in 2 easy steps /s

  1. Write a function remember (name it whatever you want) that accepts a query string as input, reads your memory provider (vector db, in memory store, idc), and returns a formatted string with the information you'd like to recall. Add it as an action into your GPTIO config.
  2. In the afterAction, save the result in your memory, better yet, tag it with action.name.

Or, feel free to deal with this.


If it’s missing a feature, do contribute to this repo, or just copy the source code– there isn’t a lot.