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

common-chatgpt

v1.0.8

Published

This generic module helps in integrating ChatGPT to your any project.

Downloads

21

Readme

Common ChatGPT

common-chatgpt is a Node.js module that provides an easy way to integrate OpenAI's powerful language model, GPT-3, into your any chatbot or conversational AI project.

  • Setup your ChatGPT in just 2 lines 😎

It also includes types for models provided by ChatGPT, so no need to remember all the Model names

Content:

Examples

  • WhatsApp

WhatsApp Image showing ChatGPT

  • Discord

Discord Image showing ChatGPT

Installation

npm i generic-chatgpt

Usage

  • WhatsApp

    • Javascript

whatsapp-web.js - Javascript

const { Client } = require('whatsapp-web.js'); // -------------|
const { Chat } = require('common-chatgpt'); //                 |
const qrcode = require('qrcode-terminal'); //                  |-- Client Setup
//                                                             |
const client = new Client(); // -------------------------------|

// setup `chat`                                                    1st `LINE`
const chat = new Chat({
  apiKey: process.env.CHAT_GPT_KEY,
  // ... see configurations and default values below
});


client.on('qr', (qr) => { // ----------------------------------|
  qrcode.generate(qr, { small: true }); //                     |
  console.log('QR RECEIVED', qr); //                           |-- For getting QR, check `whatsapp-web.js`
  //                                                           |
}); // --------------------------------------------------------|

client.on('message_create', async (msg) => {
  if (msg.id.remote === process.env.WA_CHAT_ID && !msg.fromMe) {

    // get response in single line                                 2nd `LINE`
    const chatgpt_response = await chat.getMessage(msg.body, msg.author);

    // send it anywhere
    client.sendMessage(process.env.WA_CHAT_ID, chatgpt_response);

  }
});

client.initialize();
  • Typescript

whatsapp-web.js - Typescript

import * as WAWebJS from 'whatsapp-web.js'; // ----------------|
import { Client } from 'whatsapp-web.js'; //                   |
import qrcode from 'qrcode-terminal'; //                       |-- Client Setup
import { Chat } from 'common-chatgpt'; //                      |
const client = new Client({}); // -----------------------------|

// setup `chat`                                                    1st `LINE`
const chat = new Chat({
  apiKey: process.env.CHAT_GPT_KEY as string,
  // ... see configurations and default values below
});

client.on('qr', (qr: string) => { // --------------------------|
  qrcode.generate(qr, { small: true }); //                     |
  console.log('QR RECEIVED', qr); //                           |-- For getting QR, check `whatsapp-web.js`
  //                                                           |
}); // --------------------------------------------------------|

client.on('message_create', async (msg: WAWebJS.Message) => {
  if (msg.id.remote === (process.env.WA_CHAT_ID as string) && !msg.fromMe) {

    // get response in single line                                 2nd `LINE`
    const chatgpt_response = await chat.getMessage(msg.body, msg.author ?? '');

    // send it anywhere
    client.sendMessage(process.env.WA_CHAT_ID as string, chatgpt_response);
  }
});

client.initialize();
  • Discord

    • Javascript-D
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { Chat } = require('common-chatgpt'); //                 |
require('dotenv/config'); //                                   |
 //                                                            |
const client = new Client({ //                                 |
  intents: [ //                                                |
    GatewayIntentBits.Guilds, //                               |
    GatewayIntentBits.GuildMessages, //                        |
    GatewayIntentBits.MessageContent, //                       |
  ], //                                                        |-- Client Setup
}); //                                                         |
//                                                             |
client.once(Events.ClientReady, (clientUser) => { //           |
  console.log(`Logged in as ${clientUser.user.tag}`); //       |
}); //                                                         |
 //                                                            |
const BOT_CHANNEL = '1075363634479374376'; //                  |
//                                                             |
client.login(process.env.BOT_TOKEN); // -----------------------|

// setup `chat`                                                    1st `LINE`
const chat = new Chat({
  apiKey: process.env.CHAT_GPT_KEY as string,
    // ... see configurations and default values below
});

client.on(Events.MessageCreate, async (message) => {
  if (message.author.bot) return;
  if (message.channel.id !== BOT_CHANNEL) return;

    // get response in single line                                 2nd `LINE`
  const chatgpt_response = await chat.getMessage(
    message.content,
    message.member.displayName
  );

    // send it anywhere
  await message.channel.send(chatgpt_response);
});

Model types

type Model = 'text-davinci-003' | 'text-curie-001' | 'text-babbage-001' | 'text-ada-001';

Default Configs

{
    model: "text-davinci-003",
    max_token: 300,
    temprature: 0.8,
}

Contributing

We welcome contributions from anyone who is interested in improving common-chatgpt. To get started, please follow these steps:

  1. Fork this repository to your own account.
  2. Create a new branch with a descriptive name (git checkout -b my-new-feature).
  3. Implement your new feature or bug fix.
  4. Commit your changes with commit messages (git commit -am 'Add some feature').
  5. Push your branch to your fork (git push origin my-new-feature).
  6. Submit a pull request

Author

Piyush Duggal

Email: [email protected] Checkout my other projects.

License

The MIT License (MIT)

Copyright (c) 2023 Piyush Duggal