code-yeongyu / AiShell

AiShell: A Natural Language Shell like GitHub Copilot X, Powered by ChatGPT
MIT License
151 stars 14 forks source link

SSL handshake failure while connecting to OpenAI API server using Brave browser #52

Closed xshapira closed 1 year ago

xshapira commented 1 year ago

It seems there’s an SSL handshake failure while attempting to establish a secure connection with the OpenAI API server.

When running the following command:

aishell 'print Hello World'

I'm getting this error:

SSLError: HTTPSConnectionPool(host='explorer.api.openai.com', port=443): Max retries
exceeded with url: /api/auth/session (Caused by SSLError(SSLError(1, '[SSL:
SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:992)')))

Are there any specific Brave browser settings that could be causing this issue?

code-yeongyu commented 1 year ago

Guess the problem of revChatGPT? have you tried with the openai official api or the reverse engineered api?

Sorry for the late answer BTW

luxkatana commented 1 year ago

having the same issue! I am using the reverse engineering one.

Browser: Firefox SSLError: HTTPSConnectionPool(host='explorer.api.openai.com', port=443): Max retries exceeded with url: /api/auth/session (Caused by SSLError(SSLError(1, '[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:992)')))

code-yeongyu commented 1 year ago

Currently recommend to use Official API, but i am looking into this and will fix ASAP. sorry 😞

code-yeongyu commented 1 year ago
  1. The cookie parsing feature retrieves the 'session token` from the given browser.
  2. The session token no longer works as OpenAI's ChatGPT authentication method
  3. access token now works instead of session token
  4. Since access token can be expired easily, I think I have to add an option to the AiShell Config: default browser and to retrieve access token, every time the user queries.
code-yeongyu commented 1 year ago

I am super busy now so expecting to be fixed not very soon, so now just recommend to use Official API. πŸ˜“ Thanks!

code-yeongyu commented 1 year ago

As a solution of this, I am thinking of:

  1. Update config json like following

    {
    "language_model": "reverse_engineered_chatgpt",
    "openai_api_key": null,
    "browser": "brave" // firefox, chrome, safari or whatever
    }
  2. Replace session token retrieving code as access token retrieving code

    • Using the browser's cookie, send request to https://chat.openai.com/api/auth/session to get the access token
  3. Send request to ChatGPT using configured information from 2

xshapira commented 1 year ago

As a solution of this, I am thinking of:

  1. Update config json like following
{
  "language_model": "reverse_engineered_chatgpt",
  "openai_api_key": null,
  "browser": "brave" // firefox, chrome, safari or whatever
}
  1. Replace session token retrieving code as access token retrieving code
  • Using the browser's cookie, send request to https://chat.openai.com/api/auth/session to get the access token
  1. Send request to ChatGPT using configured information from 2

This looks good! Reverse engineering is really useful for ChatGPT Plus subscribers. Do you know when you'll release an update?

Thanks for the hard work πŸ‘

code-yeongyu commented 1 year ago

I am guessing within a week! πŸ‘ Thank you πŸ™Œ

code-yeongyu commented 1 year ago

@xshapira FYI, before I update, You can use aishell by doing following:

  1. You can visit https://chat.openai.com/api/auth/session to get the access token
  2. and manually set access token into the json file (~/.aishell_config.json)
xshapira commented 1 year ago

@xshapira FYI, before I update, You can use aishell by doing following:

  1. You can visit https://chat.openai.com/api/auth/session to get the access token
  2. and manually set access token into the json file (~/.aishell_config.json)

I followed your instructions but got this error (have the same issue with the younger brother of this project, YGK-a):

Screen Shot 1

code-yeongyu commented 1 year ago

it definetely looks like because of the version of revchatgpt, i am going to bump up that.

code-yeongyu commented 1 year ago

Just released new version with version up. Guess now it's gonna work.

Plus, if you have further issues with YGK-a, please issue it on YGK-a. Thanks!

xshapira commented 1 year ago

Just released new version with version up. Guess now it's gonna work.

Plus, if you have further issues with YGK-a, please issue it on YGK-a. Thanks!

Works like a charm! Thank you πŸ‘

code-yeongyu commented 1 year ago

Hey @xshapira! I've just released a new version featuring automatic browser login using access tokens! #56

Now, every time you make a request, it retrieves a fresh access token using your credentials from your chosen browser. Although this is a breaking change, you'll need to set up AiShell once more, but it shouldn't be too bothersome as all you need to do is select your preferred browser. And this patch also have done to ygka too. (They now share the same config)

Thank you for using the AiShell!