Zero6992 / chatGPT-discord-bot

Integrate ChatGPT into your own discord bot
GNU General Public License v2.0
2.6k stars 699 forks source link

UNOFFICIAL API Access #365

Closed opsec-warehouse closed 1 year ago

opsec-warehouse commented 1 year ago

There's either a bug with the code directly (which I can't find) or I'm configuring the local .env incorrectly.

Upon attempting to utilize the UNOFFICIAL API, I define the PUID and ACCESS_TOKEN in .env, and then attempt to start the server; this is the error I get:

// custom code added in src/aclient.py to see variables before they're sent to **revChatGPT**
Email => [REDACTED]
Passwd => [REDACTED]
Access Token => [REDACTED]
Model => gpt-4
Paid => True

// Raw Error itself
Traceback (most recent call last):
  File "/home/gpt/chatGPT-discord-bot/./main.py", line 1, in <module>
    from src import bot
  File "/home/gpt/chatGPT-discord-bot/src/bot.py", line 5, in <module>
    from src.aclient import client
  File "/home/gpt/chatGPT-discord-bot/src/aclient.py", line 163, in <module>
    client = aclient()
             ^^^^^^^^^
  File "/home/gpt/chatGPT-discord-bot/src/aclient.py", line 40, in __init__
    self.chatbot = self.get_chatbot_model()
                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gpt/chatGPT-discord-bot/src/aclient.py", line 46, in get_chatbot_model
    return AsyncChatbot(config={"email": self.openAI_email, "password": self.openAI_password, "access_token": self.chatgpt_access_token, "model": self.openAI_gpt_engine, "paid": self.chatgpt_paid})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gpt/chatGPT-discord-bot/venv/lib/python3.11/site-packages/revChatGPT/V1.py", line 797, in __init__
    super().__init__(
  File "/home/gpt/chatGPT-discord-bot/venv/lib/python3.11/site-packages/revChatGPT/V1.py", line 66, in wrapper
    out = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/gpt/chatGPT-discord-bot/venv/lib/python3.11/site-packages/revChatGPT/V1.py", line 141, in __init__
    cached_access_token = self.__get_cached_access_token(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gpt/chatGPT-discord-bot/venv/lib/python3.11/site-packages/revChatGPT/V1.py", line 66, in wrapper
    out = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/gpt/chatGPT-discord-bot/venv/lib/python3.11/site-packages/revChatGPT/V1.py", line 260, in __get_cached_access_token
    s_access_token[1] += "=" * ((4 - len(s_access_token[1]) % 4) % 4)
    ~~~~~~~~~~~~~~^^^
IndexError: list index out of range

When extracting the PUID and ACCESS_CODE, the instructions on the readme.md were unclear, so I attempted to paste both URL-encoded and URL-decoded and neither have worked. To my knowledge, the _puid cookie in chat.openai.com uses this syntax:

user-o0kexO6gM8pM3q6nM5kS5rFB:4414848814-RhkCCWNEU8iIBm1wHA==

split apart, it seems to be a 24-char user identifier "user-o0kexO6gM8pM3q6nM5kS5rFB", trailed by another 10-digit ID of some sort "4414848814", and ultimately followed by an encrypted object that's been base64 encoded.

Does this entire PUID need to be added in the .env while URL-encoded or decoded, and what sections (or all?) of the PUID are to be added to the config?

opsec-warehouse commented 1 year ago

Found the issue. The problem was that revChatGPT was storing the configuration variables in a separate file on the user root and was ignoring the .env created in the root of chatGPT-discord-bot.

To fix, you'll want to grab the accessToken object from https://chat.openai.com/api/auth/session (post-authentication) and copy/paste it directly into the revChatGPT configuration file.

The cached revChatGPT configuration can be found at ~/.config/revChatGPT/cache.json