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

gpt-var

v1.0.24

Published

## Overview

Downloads

6

Readme

README for GPTVAR

Overview

GPTVAR facilitates easy communication with the OpenAI API, enabling the seamless sending of prompts and receiving of responses. it can be adapted for other models, simplifying the creation of values for variables using GPT-generated content.

Prerequisites

  • Node.js
  • An OpenAI API key

Installation

Install GPTVAR using npm:

npm install gpt-var

Quick Start

Utilize GPTVAR in a few simple steps:

  1. Import the Class

    Begin by importing GPTVAR into your TypeScript file:

    import GPTVAR from 'gpt-var';
  2. Create an Instance

    Initialize GPTVAR with your OpenAI API key and, optionally, your preferred model. For a list of models, visit OpenAI Models Overview.

    const gptVar = new GPTVAR('your-openai-api-key', 'model-name');
  3. Send a Prompt

    Call prompt with your message and the desired format. Formats can be 'any', 'array', 'object', or 'objectInArray'.

    gptVar.prompt('Your prompt here', 'any').then(response => {
      console.log(response);
    }).catch(error => {
      console.error(error);
    });
  4. Handle Responses

    prompt returns a promise with the GPT model's response, which you can then process as needed.

Method

prompt(message: string, format: string)

This method sends a message to the GPT model, expecting a response in the specified format.

  • messages: The input string for the GPT model.
  • format: The expected response format. Options:
    • any: Returns a raw string, suitable for flexible or unspecified formats.
    • object: Expects a JSON object, ideal for structured data.
    • array: Expects a JSON array, great for lists or sequences.
    • objectInArray: Expects an array of JSON objects, useful for structured lists.

Example Usage:

  1. Format: any

    Returns the response as a raw string, ideal for unstructured data.

    gptVar.prompt('Tell me a joke', 'any').then(response => {
      console.log('Response:', response);
    });

    Example Response:

    "Why don't scientists trust atoms? Because they make up everything!"
  2. Format: object

    Expects a JSON object response.

    gptVar.prompt('Provide details about the Eiffel Tower', 'object').then(response => {
      console.log('Response:', response);
    });

    Example Response:

    {
      "name": "Eiffel Tower",
      "location": "Paris, France",
      "height": "300 meters"
    }
  3. Format: array

    Expects a JSON array response.

    gptVar.prompt('List three famous scientists', 'array').then(response => {
      console.log('Response:', response);
    });

    Example Response:

    ["Albert Einstein", "Marie Curie", "Isaac Newton"]
  4. Format: objectInArray

    Expects an array of JSON objects.

     gptVar.prompt('List major cities with their countries and populations', 'objectInArray').then(response => {
       console.log('Response:', response);
     });

    Example Response:

     [
       {
         "city": "New York City",
         "country": "USA",
         "population": "8.4 million"
       },
       {
         "city": "Tokyo",
         "country": "Japan",
         "population": "9.3 million"
       },
       {
         "city": "London",
         "country": "UK",
         "population": "8.9 million"
       }
     ]

Notes

  • Ensure your OpenAI API key is valid.
  • Default model is 'gpt-3.5-turbo'; other models can be specified.
  • Adjust the response format to meet your needs.

Support

For support, issues, or feature requests, please file an issue on our GitHub repository.