1.0.23 • Published 3 days ago

pptr-gpt v1.0.23

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

PPTR-GPT - Node.js ChatGPT Module

This Node.js module allows you to interact with the ChatGPT website(https://chat.openai.com) using Puppeteer. It enables you to send messages to ChatGPT and receive responses, as well as create conversational sessions with the ability to send multiple messages and retrieve the conversation history.

Installation

To install the module, run the following command:

npm install pptr-gpt 
# or global
npm install pptr-gpt -g

Usage

First, import the required functions from the module:

const chatGpt = require('pptr-gpt');

Initialization

Before using the module, you need to initialize Puppeteer:

await chatGpt.init()

Single message

To send a single message to ChatGPT and receive the response, use the singleMessage function:

const answer = await chatGpt.singleMessage(`Write a story about dog, software engineer, and node.js`);
console.log(answer);

Create Chat Session

To create a conversational session with ChatGPT, use the createChat function:

const chat = await chatGpt.createChat("How to write a todo app on node.js?");
console.log(chat.response);

The createChat function returns an object with the following properties and methods:

  • response (string): The initial response from ChatGPT.
  • history (array): An array containing the conversation history, with each element representing a message exchange between the user and ChatGPT.
  • send (function): A function that allows you to send additional messages to ChatGPT during the conversation. It returns a Promise that resolves with the response from ChatGPT.
  • close (function): A function that closes the current chat session.

Example of sending additional messages:

const nextResponse = await chat.send("Ok. And how to write this on python?");
console.log(nextResponse);
console.log('history', chat.history);

Closing Sessions

After you're done using the module, you should close the Puppeteer session:

await chatGpt.close();

Example

Here's a complete example that demonstrates the usage of the module:

const chatGpt = require('pptr-gpt');

const test = async () => {
  await chatGpt.init();

  const answer = await chatGpt.singleMessage(`Write a story about dog, software engineer, and node.js`);
  console.log("---Single Message---");
  console.log(answer)
  console.log("--------------------");

  const chat = await chatGpt.createChat("How to write a todo app on node.js?");
  console.log("----Create Chat-----");
  console.log(chat.response);
  console.log("--------------------");

  const nextResponse = await chat.send("Ok. And how to write this on python?");
  console.log("----Next Response----");
  console.log(nextResponse);
  console.log('--------------------');
  console.log('history', chat.history);

  await chat.close();
  await chatGpt.close();
};

test();

This example demonstrates the following:

  1. Initializing the module.
  2. Sending a single message to ChatGPT and logging the response.
  3. Creating a chat session and logging the initial response.
  4. Sending an additional message during the chat session and logging the response.
  5. Logging the conversation history.
  6. Closing the chat session and Puppeteer session.
1.0.19

3 days ago

1.0.22

3 days ago

1.0.21

3 days ago

1.0.20

3 days ago

1.0.23

3 days ago

1.0.18

28 days ago

1.0.17

28 days ago

1.0.16

28 days ago

1.0.11

28 days ago

1.0.15

28 days ago

1.0.14

28 days ago

1.0.13

28 days ago

1.0.12

28 days ago

1.0.10

29 days ago

1.0.9

29 days ago

1.0.8

29 days ago

1.0.7

1 month ago

0.0.6

1 month ago

0.0.5

1 month ago

0.0.4

1 month ago

0.0.3

1 month ago

0.0.2

1 month ago