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

quickgpt

v0.2.5

Published

An incredibly easy-to-use wrapper for the OpenAI API

Downloads

871

Readme

QuickGPT

QuickGPT is an incredibly easy-to-use wrapper for the OpenAI API. It's designed to simplify your interaction with OpenAI's powerful models, so you can focus on asking questions and getting answers without worrying about the complexity of the official API.

Why QuickGPT?

QuickGPT is designed to make interacting with OpenAI's API incredibly easy while offering essential customization options. You can quickly set the most commonly used configurations, such as model, format, and maximum tokens, using setModel(), setFormat(), and setMaxToken(), ensuring a hassle-free experience without the need to configure every request manually.

It also features unique functions such as JustAnswer, ELI5, TrueOrFalse, and YesOrNo. These allow you to receive direct answers, concise explanations, straightforward true/false evaluations, or quick yes/no decisions, making them especially beneficial for programming and decision-making tasks.

In short, QuickGPT streamlines OpenAI API usage, giving you both power and simplicity, so you can focus on getting the answers you need.

Installation

Install QuickGPT via npm:

npm install quickgpt

Usage

To get started with QuickGPT, you'll need to either:

Set your OpenAI API key as an environment variable, or use a package like dotenv.

(unix/linux)
export OPENAI_API_KEY=your-api-key

(if you use .env)
OPENAI_API_KEY=your-api-key

Or pass the API key directly when initializing QuickGPT.

import QuickGPT from 'quickgpt';
// or if you need to use require
const QuickGPT = require('quickgpt').default;

const gpt = new QuickGPT({ apiKey: 'your-api-key' });

Basic Configuration

To get started with QuickGPT, you'll need to configure some basic settings. You can use the following methods to set up your preferences.

setModel(model: string): void;
setFormat(format: boolean): void;
setMaxToken(token: number): void;

Default Values:

  • model: 'gpt-4o'
  • format: false
  • maxToken: 1000

Details:

  • Model Options: Choose one from 'gpt-4' | 'gpt-4o' | 'gpt-4o-mini'
    • This library includes only three options, as most users will likely choose one of these. Feel free to submit request if needed!
  • Format: Specify whether to use LaTeX, Markdown, or HTML.
  • Max Tokens: Represents the maximum number of tokens to use in the response.

Example

// Import the QuickGPT class
import QuickGPT from 'quickgpt';
// or if you need to use require
const QuickGPT = require('quickgpt').default;

// If you've already set the OPENAI_API_KEY as an environment variable:
const gpt = new QuickGPT();
// Alternatively, you can pass the API key directly:
const gpt = new QuickGPT({
    apiKey: process.env.OPENAI_API_KEY || 'your-api-key',
});

// Use any method of your choice to get a response
const response = await gpt.JustAnswer('limit of 1/x as x approaches infinity');
console.log(response);
// -> As x gets bigger and bigger, 1 divided by x gets smaller and smaller. So, the limit of 1/x as x approaches infinity is 0.

// You can handle as a promise too
gpt.Explain('limit of 1/x as x approaches infinity').then(console.log);
// -> The limit of 1/x as x approaches infinity is 0. As the value of x becomes larger and larger, the value of 1/x becomes smaller and closer to 0. This is because you are dividing 1 by an increasingly large number, which reduces the overall value towards zero.

gpt.ELI5('limit of 1/x as x approaches infinity').then(console.log);
// -> As x gets bigger and bigger, like when you count up to really large numbers, the fraction 1/x becomes a smaller and smaller piece because you're dividing 1 by a bigger number each time. It's like if you have one cookie and you share it with more and more friends, each friend gets a tinier and tinier piece. So, as x goes to infinity, 1/x gets closer and closer to 0. That's the limit!

// You can pass an image URL as the second parameter
const imageURL =
    'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006_%28square%29.jpg/187px-Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006_%28square%29.jpg';
gpt.ELI5('what is this image?', imageURL).then(console.log);
// -> This is an image of Mount Everest, the highest mountain in the world, located in the Himalayas on the border between Nepal and Tibet.

// from now on, lets enable formats like latex, markdown, html
gpt.setFormat(true);

gpt.JustAnswer('limit of 1/x as x approaches infinity').then(console.log);
// -> As \( x \) gets really, really big, like infinity, \(\frac{1}{x}\) gets really, really small, like zero. So, the limit of \(\frac{1}{x}\) as \( x \) goes to infinity is 0.

// You can create custom completion function, pass the system prompt to createCustomCompletion.
const askHeadhunter = gpt.createCustomCompletion(
    'You are a headhunter for a tech company.',
);
const headhunterJobDescription = await askHeadhunter(
    'What is your job? Say in a sentence.',
);
console.log(headhunterJobDescription);
// -> I identify and recruit talented professionals for a tech company to meet its hiring needs.

// finally, if you want to directly use the official OpenAI API
const openai = gpt.openai;

Easy Contribution

If you have ideas for new features, feel free to contribute! The project is designed so anyone can easily add functionality through merge requests.

Developing the library

To make changes to the library, please follow these steps:

  1. Clone the Repository
    Start by cloning the repository to your local machine using the following command:

    git clone https://github.com/hw4n/quickgpt
  2. Install Dependencies
    Navigate to the cloned directory and ensure you have all the necessary dependencies and development dependencies installed by running the following command:

    npm install
  3. Development Build and Testing
    During development, you can use the following command to rebuild and test automatically:

     npm run start:dev

    This command will execute the dev.js file with the environmental variable NODE_ENV set to development, which is useful for testing the changes you've made to the library.

    Additionally, you can simplify development by adding your OPENAI_API_KEY to the .env file, allowing the library to access the OpenAI API without hardcoding your key in the code.

    (.env)
    
    OPENAI_API_KEY=your-api-key