KudoAI / chatgpt.js

🤖 A powerful, open source client-side JavaScript library for ChatGPT
https://chatgpt.js.org
MIT License
1.91k stars 142 forks source link

Failed to load as a Greasemonkey script #178

Closed pramatias closed 9 months ago

pramatias commented 9 months ago

I tried running the following script, and every object prefixed with: chatgpt. returns null. Greasemonkey did download the minified chatgpt js file, but it cannot work at all with the object chatgpt . chatgpt.getLastReply, chatgpt.getLastResponse all return null.

// ==UserScript== // @name ChatGPT Userscript // @description A Greasemonkey template to start using chatgpt.js like a boss // @author chatgpt.js // @namespace https://chatgpt.js.org // @version 2024.1.28 // @match https://chat.openai.com/* // @icon https://raw.githubusercontent.com/kudoai/chatgpt.js-greasemonkey-starter/main/media/images/icons/robot/icon48.png // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.6.4/dist/chatgpt-2.6.4.min.js // @grant GM_getValue // @grant GM_setValue // @noframes // @homepageURL https://github.com/kudoai/chatgpt.js-greasemonkey-starter // ==/UserScript==

(async () => { // Init config console.log("Inside async ");

// Print chatgpt.js methods
await chatgpt.isLoaded(); 
console.log("Past GPT loading ");

function logHello() {
       (async () => {
                    console.log("Hello again");
       try {
          let lastResponse = await chatgpt.getLastReply();

          if (typeof lastResponse === 'string') {
              console.log("Hello " + lastResponse);
          } else {
              console.error("Hello Error: lastResponse is not a string");
          }   

               console.log("Hello " + lastResponse);
          } catch (error) {
              console.error("Async Hello Error:", error);
          }
      })();
 }
// Run the logger when the DOM is ready
window.addEventListener('DOMContentLoaded', logHello());

})();

adamlui commented 9 months ago

hi @pramatias thank you for opening the issue. The synonymization routine that generates function aliases like getLastReply is bugged so that one specifically doesn't work (nearly all the other ones generated using https://github.com/KudoAI/chatgpt.js/blob/main/data/function-aliases.json work) but you can reference the userguide for the names of the root methods, in this case it is getLastResponse

But I just tested it, there is a new key error probably because OpenAI updated the API so I have to fix it first, but check out the other methods in the userguide

adamlui commented 9 months ago

@pramatias I think this key error is recent like past couple days, for some reason I cannot send second messages to ChatGPT

image

pramatias commented 9 months ago

Hello, @adamlui thanks for the reply. If the issue is fixed, i close the issue.