theAbdoSabbagh / UnlimitedGPT

An unofficial Python wrapper for OpenAI's ChatGPT API
https://pypi.org/project/UnlimitedGPT/
GNU General Public License v3.0
364 stars 42 forks source link

Two session tokens, neither works #3

Closed CoderGreensparrow closed 1 year ago

CoderGreensparrow commented 1 year ago

I am a free user of ChatGPT through a google account login. When I looked at the cookies, there were two cookies starting with "Secure-next-auth.session-token": Secure-next-auth.session-token.1 __Secure-next-auth.session-token.0 Neither works when inputted as the session token. kép My code (it's for a project):

import re
from UnlimitedGPT import ChatGPT, ChatGPTResponse
import logging

# Maintenence strings
M_SETUP = """"""  # I removed that large string. It's probably not the issue.
M_SHORTEN = """"""

class BackendChatGPT:
    def __init__(self, session_token: str, *, setup_message: str = None):
        """
        A backend for ChatGPT to make programming easier.
        :param session_token: The session_id from chat.openai.com. Not saved in THIS class.
        :param setup_message: The message used for getting ChatGPT "in the mood" and making it know what situation it is put in.
        """
        if not setup_message: setup_message = M_SETUP
        self.gpt = ChatGPT(session_token)
        set_up = False
        while not set_up:
            result = self.send_message(setup_message, filter=False)
            if re.fullmatch(r"\W*?ready\W*", result.response, re.IGNORECASE):
                set_up = True

    def send_message(self, message: str, *, filter: bool = True):
        ok = False
        i = -1
        while not ok and i < 10:
            i += 1
            logging.debug("IN: " + message)
            result = self.gpt.send_message(message)  # setup text
            logging.debug("OUT: " + result.response)
            if filter:
                if result.response.lower().startswith("!important") and len(result.response) <= 1000:
                    ok = True
                elif len(result.response) <= 100:
                    ok = True
                else:
                    message = M_SHORTEN
            else:
                ok = True
        if i == 10:
            return ChatGPTResponse("Error. Responses too large.")
        return result

    def reset(self):
        self.gpt.reset_conversation()

def test():
    logging.basicConfig(level=logging.DEBUG)
    gpt = BackendChatGPT("")  # HERE GOES THE SESSION TOKEN
    gpt.send_message("Hello, ChatGPT!")
if __name__ == '__main__':
    test()

ValueError after using token.0:

ValueError: Invalid session token
theAbdoSabbagh commented 1 year ago

There shouldn't be 2 session tokens, and I see you're initializing the class correctly, so the error is because of the session token indeed. Go to your browser settings and clear all data and cookies from the ChatGPT website, perhaps even OpenAI as a whole. Then login again and try to get the session token, there should be one only. Lemme know if that works.

theAbdoSabbagh commented 1 year ago

As you can see, for me there is only one session-token cookie, which is how it should be. (Ignore callback-url, that one is not required by the library) image

CoderGreensparrow commented 1 year ago

Weird... I mostly use Librewolf and just installed Google Chrome back on my laptop today. I cleared cookies and website data in both (EVERY site data, so even google stuff get's deleted, because I don't know what's causing this), the session tokens were still there. I even opened it up in ungoogled-chromium (which I don't use a lot) in a guest instance and tried there. Same thing.

Maybe there's something with my OpenAI account?

theAbdoSabbagh commented 1 year ago

That's really weird, perhaps it's your account yeah. Could you try with a different account? This is my first time seeing an account with two session tokens.

CoderGreensparrow commented 1 year ago

I just started making an account today (whose setup I didn't finish) with another email. I finished that and that has one session token! I don't know what I did to have two. Now the session token works it looks like and now the program is breaking differently. I'll look into it. Thanks for the help! :)

theAbdoSabbagh commented 1 year ago

Sure! If you face an issue with the library don't hesitate to make another issue!