What about the unavailability of OpenAI's API in Celestial Empire?

What about the unavailability of OpenAI's API in Celestial Empire?

·

3 min read

Atank © 2023

Note: As English is my second language, I have relied on ChatGPT to optimize my article.

1. Obstructing the sky and covering the sun

As we all know, there is a thing called the Great Firewall in China, which confines the citizens to an abyss and tells them to have national confidence and not to believe in such nonsense under coercion and temptation. I used to believe in this kind of nonsense, living in a garbage dump inside the wall, pretending to be very confident, until my knowledge grew inside and outside the wall, and I found that I looked very stupid before.

The birth of ChatGPT has given everyone on Earth the opportunity to participate in the journey of violent cracking the truth of the world. It is not surprising that the Great Firewall is still an obstacle in front of the citizens who are trying to use OpenAI API.

The development of technology has allowed many of us to see such beautiful scenery:

At the same time, friends who want to further learn to use OpenAI API may still encounter such frustrating scenes:

Yes, it was the wall that made your connection always timeout.

2. Removing obstacles

Seeing that classmates are encountering API timeout problems one after another, I am very puzzled:

Since we have all seen the "beautiful scenery" mentioned earlier, doesn't that mean we have already have “exposed to the sun”? Why doesn't it work when using OpenAI API?

After communicating with classmates and experimenting, we have successfully identified the problem:

we may have "exposed to the sun" at the browser level, but not at the terminal level.

2.1 How to know if you have "exposed to the sun"?

  • For Desktop

  • For bash or zsh or powershell

    • Type the command curl ipinfo.io in the shell.

If you find that you have not "exposed to the sun", then OpenAI's API call timeout may be due to this.

2.2 How to get the proxy to start working at the terminal?

  • For zsh

    • Use the command cd ~ to go back to the home directory, open the .zprofile file with nano or vim (sudo nano .zprofile) and add the following code to the end of the file, then save and exit.

        #in ZSH, add to ~/.zprofile
      
        set_http_proxy() {
          if [ -e $HOME/.proxyrc ]; then
            . $HOME/.proxyrc
          fi
      
          if [ -z $http_proxy ]; then
            echo "No proxy config, environment found, connection attempt failed."
            echo "Let's setup a config or update your password."
        #   read 'eid?eID: '
        #   read -s 'password?Password: '
            http_proxy="http://127.0.0.1:<port>/" # If you don't know the port number, ask your proxy service provider.
            https_proxy="http://127.0.0.1:<port>/" # If you don't know the port number, ask your proxy service provider.
            echo "export http_proxy=$http_proxy" > $HOME/.proxyrc
            echo "export HTTP_PROXY=$http_proxy" >> $HOME/.proxyrc
            echo "export https_proxy=$https_proxy" >> $HOME/.proxyrc
            echo "export HTTPS_PROXY=$https_proxy" >> $HOME/.proxyrc
            . $HOME/.proxyrc
          fi
        }
      
        kill_http_proxy() {
          rm $HOME/.proxyrc
          unset_http_proxy
        }
      
        unset_http_proxy() {
          unset http_proxy
          unset HTTP_PROXY
          unset https_proxy
          unset HTTPS_PROXY
        }
      
        # set the proxy
        set_http_proxy
      
    • Close the terminal and reopen it, type curl ipinfo.io to check the IP location, and see if you have "exposed to the sun".

  • For bash

    • Use the command cd ~ to go back to the home directory, open the .bash_profile file with nano or vim (sudo nano .bash_profile) and add the following code to the end of the file, then save and exit.

    • Other parts refer to the above zsh operation steps.

  • For powershell

  • After configuring the terminal proxy above, OpenAI's API should be available.