C-Nedelcu / talk-to-chatgpt

Talk to ChatGPT AI using your voice and listen to its answers through a voice
GNU Affero General Public License v3.0
1.97k stars 331 forks source link

New OpenAI model update solution #252

Open hoshizorista opened 1 month ago

hoshizorista commented 1 month ago

Hey guys! again OpenAI changed its selectors for chatgpt and broke the extension, I managed to fixed it, check out the fork I made at my profile, well work to keep it updated and bring some cool new functions in the near future

If you dont really want to check the fork and youre a bit code-wise heres the updated functions u need to change on content.js to update it:

1st, look for function CN_CheckNewMessages() and replace the entire function with:

// Check for new messages the bot has sent. If a new message is found, it will be read out loud
function CN_CheckNewMessages() {
    // Any new messages?
    var currentMessageCount = document.querySelectorAll('.text-message').length
    if (currentMessageCount > CN_MESSAGE_COUNT) {
        // New message!
        console.log("New message detected! current message count: " + currentMessageCount);
        CN_MESSAGE_COUNT = currentMessageCount;
        CN_CURRENT_MESSAGE = document.querySelectorAll('.text-message')[currentMessageCount - 1];
        CN_CURRENT_MESSAGE_SENTENCES = []; // Reset list of parts already spoken
        CN_CURRENT_MESSAGE_SENTENCES_NEXT_READ = 0;
    }

    // Split current message into parts
    if (CN_CURRENT_MESSAGE) {
        var currentText = document.querySelectorAll('.text-message')[currentMessageCount - 1].innerText + "";
        //console.log("currentText:" + currentText);

        // Remove code blocks?
        if (CN_IGNORE_CODE_BLOCKS) {
            currentText = ""
            document.querySelectorAll('.text-message')[currentMessageCount - 1].querySelectorAll(".markdown > :not(pre)").forEach(n => {
                currentText += n.innerText
            });
            ////console.log("[CODE] currentText:" + currentText);
        }

        var newSentences = CN_SplitIntoSentences(currentText);
        if (newSentences != null && newSentences.length != CN_CURRENT_MESSAGE_SENTENCES.length) {
            ////console.log("[NEW SENTENCES] newSentences:" + newSentences.length);

            // There is a new part of a sentence!
            var nextRead = CN_CURRENT_MESSAGE_SENTENCES_NEXT_READ;
            for (let i = nextRead; i < newSentences.length; i++) {
                CN_CURRENT_MESSAGE_SENTENCES_NEXT_READ = i+1;

                var lastPart = newSentences[i];
                //console.log("Will say sentence out loud: "+lastPart);
                CN_SayOutLoud(lastPart);
            }
            CN_CURRENT_MESSAGE_SENTENCES = newSentences;
        }
    }

    setTimeout(CN_CheckNewMessages, 100);
}

2nd: look for var currentMessageCount = document.querySelectorAll('.text-base .items-start').length; and replace it with

        var currentMessageCount = document.querySelectorAll('.text-message').length;
hoshizorista commented 1 month ago

btw for the messages not being auto send after speech to text, just look for the comment

// Find the send button and enable it

and change the code bellow the comment to

var sendButton = jQuery("[data-testid='send-button']"); 
    if (sendButton.length) {
        sendButton.prop('disabled', false); // Force enable
        sendButton.removeAttr('disabled').removeClass('disabled');

        // Ensure the button is enabled and click it
        if (!sendButton.is(':disabled')) {
            sendButton[0].click(); // Attempt to click using DOM API
            console.log("[CN_SendMessage] Automatically clicking the send button.");
        } else {
            console.log("[CN_SendMessage] The send button is enabled but could not be clicked.");
        }
    } else {
        console.error("[CN_SendMessage] Send button not found.");
    }
deadbydonovan commented 1 month ago

@hoshizorista thank you so much, but we have a new problem. Elevenlabs has changed their API keys and the new key generations don't work with this extension, I keep getting errors, ChatGPT Says [1] ElevenLabs API error: Invalid API key. I accessed an old ElevenLabs account of mine to use the old API key and it works fine. Any ideas? I have half a million characters locked up with the new API.

hoshizorista commented 1 month ago

@deadbydonovan not really familiar with those new API keys, do they seem longer? anything particullary changed from older to newest? if you have discord lmk so i can hit you up and help you with that

i tried with my usual api key and works ok

deadbydonovan commented 1 month ago

@hoshizorista the new API Keys start with "sk_" followed by a bunch of numbers. I have a discord

hoshizorista commented 1 month ago

@hoshizorista the new API Keys start with "sk_" followed by a bunch of numbers. I have a discord

hmu on discord: exile9904

deadbydonovan commented 1 month ago

@hoshizorista I don't really know how to use Discord, but here's a server I just created to chat. https://discord.gg/kP3ssNCw or message me an invite, sorry I'm new to this.

hoshizorista commented 1 month ago

for anyone having this same error with newest ElevenLabs TTS, just go to

CN_TTS_ELEVENLABS_APIKEY = CN_RemovePunctuation(jQuery("#TTGPTElevenLabsKey").val()+"");

and replace it with

CN_TTS_ELEVENLABS_APIKEY = jQuery("#TTGPTElevenLabsKey").val()+"";

hoshizorista commented 1 month ago

(or just download the extension available at my fork)

StudioDweller commented 1 month ago

Thank you so much for maintaining this! I have a podcast about AI and we rely on it for realtime interaction with our custom GPT-based AI co-host. We are recording our next episode later today and will be sure to give you a shoutout (again). The Up Against Reality podcast really appreciates all of your efforts!

enrix507 commented 1 month ago

Hey guys! again OpenAI changed its selectors for chatgpt and broke the extension, I managed to fixed it, check out the fork I made at my profile, well work to keep it updated and bring some cool new functions in the near future

If you dont really want to check the fork and youre a bit code-wise heres the updated functions u need to change on content.js to update it:

1st, look for function CN_CheckNewMessages() and replace the entire function with:

// Check for new messages the bot has sent. If a new message is found, it will be read out loud
function CN_CheckNewMessages() {
  // Any new messages?
  var currentMessageCount = document.querySelectorAll('.text-message').length
  if (currentMessageCount > CN_MESSAGE_COUNT) {
      // New message!
      console.log("New message detected! current message count: " + currentMessageCount);
      CN_MESSAGE_COUNT = currentMessageCount;
      CN_CURRENT_MESSAGE = document.querySelectorAll('.text-message')[currentMessageCount - 1];
      CN_CURRENT_MESSAGE_SENTENCES = []; // Reset list of parts already spoken
      CN_CURRENT_MESSAGE_SENTENCES_NEXT_READ = 0;
  }

  // Split current message into parts
  if (CN_CURRENT_MESSAGE) {
      var currentText = document.querySelectorAll('.text-message')[currentMessageCount - 1].innerText + "";
      //console.log("currentText:" + currentText);

      // Remove code blocks?
      if (CN_IGNORE_CODE_BLOCKS) {
          currentText = ""
          document.querySelectorAll('.text-message')[currentMessageCount - 1].querySelectorAll(".markdown > :not(pre)").forEach(n => {
              currentText += n.innerText
          });
          ////console.log("[CODE] currentText:" + currentText);
      }

      var newSentences = CN_SplitIntoSentences(currentText);
      if (newSentences != null && newSentences.length != CN_CURRENT_MESSAGE_SENTENCES.length) {
          ////console.log("[NEW SENTENCES] newSentences:" + newSentences.length);

          // There is a new part of a sentence!
          var nextRead = CN_CURRENT_MESSAGE_SENTENCES_NEXT_READ;
          for (let i = nextRead; i < newSentences.length; i++) {
              CN_CURRENT_MESSAGE_SENTENCES_NEXT_READ = i+1;

              var lastPart = newSentences[i];
              //console.log("Will say sentence out loud: "+lastPart);
              CN_SayOutLoud(lastPart);
          }
          CN_CURRENT_MESSAGE_SENTENCES = newSentences;
      }
  }

  setTimeout(CN_CheckNewMessages, 100);
}

2nd: look for var currentMessageCount = document.querySelectorAll('.text-base .items-start').length; and replace it with

      var currentMessageCount = document.querySelectorAll('.text-message').length;

thank very much amigo