A simple Node.js wrapper for connecting to ChatGPT using official OpenAI API, which allows you to easily send requests and get responses from the API in a conversational manner.
You only need to provide your OpenAI API key (no session tokens or using pupeteer for browser automation) - get it here.
Based on this method and this Python API by acheong08. Also check out this project for a more advanced API.
You can install the package using npm:
npm install chatgpt-api-wrapper
Alternatively, you can use the src/index.ts
file from this repository directly.
import ChatGPT from 'chatgpt-api-wrapper';
const apiKey = '<YOUR_API_KEY>';
const chatGPT = new ChatGPT(apiKey);
const response = await chatGPT.ask('Hello, how are you?');
console.log(response);
Also see the example.ts file.
Sends a request to the ChatGPT API and returns the response.
Retries a request to the ChatGPT API and returns the response. If the request argument is not provided, it retries the previous request, otherwise it sends a new request in place of the previous one.
Resets the chat history.