chatgpt.js
v0.0.6
Published
A simple wrapper to allow integration with the ChatGPT beta.
Downloads
4
Readme
chatgpt.js
Interact with OpenAI's ChatGPT unofficial API programatically.
Getting Started
To start using chatgpt.js
in your project, follow this quick guide:
- Add the package with
npm i chatgpt.js -S
oryarn add chatgpt.js
- Refer to the example code below to integrate:
index.js
const GPTChat = require("../dist");
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.
Finally
Thank you so much for visiting! I hope that my code is useful to you. I'd really appreciate a ⭐ if this helped you out. Cheers! 😄