chatgpt.js

A powerful, open source client-side JavaScript library for ChatGPT
GitHub
1.92k
Created 2 years ago, last commit 12 hours ago
28 contributors
4.4k commits
Stars added on GitHub, month by month
11
12
1
2
3
4
5
6
7
8
9
10
2023
2024
Stars added on GitHub, per day, on average
Yesterday
+1
Last week
+0.3
/day
Last month
+0.6
/day
Last 12 months
+0.9
/day
README


🤖 A powerful client-side JavaScript library for ChatGPT


💡 About

chatgpt.js is a powerful JavaScript library that allows for super easy interaction w/ the ChatGPT DOM.

  • Feature-rich
  • Object-oriented
  • Easy-to-use
  • Lightweight (yet optimally performant)

⚡ Importing the library

Note

To always import the latest version (not recommended in production!) replace the versioned jsDelivr URL with: https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js/chatgpt.min.js

ES11 (2020):

(async () => {
    await import('https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.3.5/dist/chatgpt.min.js');
    // Your code here...
})();

ES5 (2009):

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.3.5/dist/chatgpt.min.js');
xhr.onload = function () {
    if (xhr.status === 200) {
        var chatgptJS = document.createElement('script');
        chatgptJS.textContent = xhr.responseText;
        document.head.append(chatgptJS);
        yourCode(); // runs your code
    }
};
xhr.send();

function yourCode() {
    // Your code here...
}

Greasemonkey:

Note

To use a starter template: kudoai/chatgpt.js-greasemonkey-starter

...
// @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.3.5/dist/chatgpt.min.js
// ==/UserScript==

// Your code here...

Chrome:

Note

To use a starter template: kudoai/chatgpt.js-chrome-starter

Since Google does not allow remote code, importing chatgpt.js locally is required:

  1. Save https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/chatgpt.js to a subdirectory (lib in this example)

  2. In project's (V3) manifest.json, add lib/chatgpt.js as a web accessible resource

    "web_accessible_resources": [{
        "matches": ["<all_urls>"],
        "resources": ["lib/chatgpt.js"]
    }],
  1. In scripts that need chatgpt.js (foreground/background alike), import it like so:
(async () => {
    await import(chrome.runtime.getURL('lib/chatgpt.js'));
    // Your code here...
})();

💾 Downloading via npm:

To download chatgpt.js for local customization, run the following command in your project's root:

npm install @kudoai/chatgpt.js

After installation, navigate to node_modules/@kudoai/chatgpt.js to find the library source.

💻 Usage

chatgpt.js was written w/ ultra flexibility in mind.

For example:

chatgpt.getLastResponse();
chatgpt.getLastReply();
chatgpt.response.getLast();
chatgpt.get('reply', 'last');

Each call equally fetches the last response. If you think it works, it probably will... so just type it!

If it didn't, check out the extended userguide, or simply submit an issue or PR and it will be integrated, ezpz!

🤖 Made with chatgpt.js

demo.mp4

Add AI to Amazon shopping.
Install / Readme / Discuss

Auto-clear your ChatGPT query history for maximum privacy.
Install / Readme / Discuss

Adds AI answers to Brave Search (powered by GPT-4o!)
Install / Readme / Discuss

Automatically continue generating multiple ChatGPT responses.
Install / Readme / Discuss

Auto-play ChatGPT responses.
Install / Readme / Discuss

Keeps ChatGPT sessions fresh to eliminate network errors + Cloudflare checks.
Install / Readme / Discuss

Adds AI answers to DuckDuckGo (powered by GPT-4o!)
Install / Readme / Discuss

Adds AI answers to Google Search (powered by Google Gemma + GPT-4o!)
Install / Readme / Discuss

Use ChatGPT in Thunderbird to enhance you emails, even with a free account!
Install / Readme / Support




If you've made something w/ chatgpt.js you want to share, email showcase@chatgptjs.org or just open a pull request!

🧠 Contributors

This library exists thanks to code, translations, issues & ideas from the following contributors: