Skip to content

PlutonusDev/chatgpt.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arlo

chatgpt.js

Interact with OpenAI's ChatGPT unofficial API programatically.


Getting Started

To start using chatgpt.js in your project, follow this quick guide:

  1. Add the package with npm i chatgpt.js -S or yarn add chatgpt.js
  2. Refer to the example code below to integrate:
Code Example (Click to Open)

index.js

const GPTChat = require("chatgpt.js");
const { authToken } = require("./config");
const sleep = require("util").promisify(setTimeout);

const chatgpt = new GPTChat.Client({ authToken });

chatgpt.once("ready", async () => {
    let resp = await chatgpt.call("hello there!").catch(e => console.log(e));
    if(!resp) return console.error("looks like something went wrong :(");
    console.log(resp);

    await sleep(10000);
    
    resp = await chatgpt.call("what is the scientific name for the common house finch?", resp.conversation).catch(e => console.log(e));
    if(!resp) return console.error("looks like something went wrong :(");
    console.log(resp);
});

chatgpt.on("debug", m => console.log(`DEBUG: ${m}`));
chatgpt.on("error", m => console.error(`ERROR: ${m}`));

/*
    Output:

    DEBUG: sessionKey updated to: (...)fqJbBV3WQ.W8IAmqiEwjO-Uyw9ub2Zsg
    {
        text: 'Hello! How can I help you today?',
        conversation: '4e294a80-5daf-4322-8077-dc4d58affa1a',
        parent_message: 'a5f3b506-232a-414f-999a-161cd1ee26b3'
    }
    DEBUG: sessionKey updated to: (...)FTpYIborA.5t64dn9PjQsM-abpr1GaYw
    DEBUG: Found cached conversation: {"id":"4e294a80-5daf-4322-8077-dc4d58affa1a","parent_id":"a5f3b506-232a-414f-999a-161cd1ee26b3"}
    {
        text: 'The scientific name for the common house finch is Haemorhous mexicanus. This species is a small, seed-eating bird native to North America. It is often found in urban and suburban areas, where it feeds on a variety of seeere it feeds on a variety of seeds and other plant material. The male of the species is easily recognizable by its bright red head and breast.',
        conversation: '4e294a80-5daf-4322-8077-dc4d58affa1a',
        parent_message: 'ab4ff136-625f-41d9-b283-2c154230b76e'
    }
*/

config.js

module.exports = {
    authToken: "YOUR-OPENAI-ACCESS-TOKEN"
}

Contributing

Before creating an issue, please ensure that it hasn't already been reported / suggested. If you would like to contribute to the codebase, please do! Fork this repository, add your edits, and submit a pull request.


License

chatgpt.js is licensed under the GPL 3.0 license. See the LICENSE file for more information. If you plan to use any part of this source code in your own bot, I would be grateful if you would include some form of credit somewhere.


Star History

About

A simple wrapper built for interacting with ChatGPT.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published