Lately, there’s probably no one who doesn’t know the AI’s name ChatGPT then eh? In addition to the surprise and admiration at an extremely intelligent AI that can answer anything, even the code, there is also a little fear. The fear is because now we can clearly see how dangerous AI is to the job opportunities of many occupations. Of course, there is also the IT industry. But there are always two sides to the problem. When the doctor was born, the magician went to practice. That is the law of competition and self-elimination of the market from time immemorial. This is also a great opportunity for you to look at yourself, gain new knowledge, upgrade your level so that you are not rejected by this market.
Talking on the sidelines is probably enough. Mainly so that you don’t panic about your future. The focus of today’s article is that I will show you how to create a Chatbot using ChatGPT in python. You do not need to log in to OpenAI’s website, just go to your Website to be able to communicate with the chat bot.
Prepare
- First, you need Create a ChatGPT account.
- Next is the account Ngrokfor those of you who want to put your bot on the internet for others to use.
- And finally Python and pip.
How to install
Step 1: You go to the website of ChatAPI. Ask it any question.
Step 2: Press F12 and go to tab Application. In the menu on the left, select Cookies > First item and find the cookie named “__Secure-next-auth.session-token”. You copy that cookie code somewhere else to use later.
Step 3: Clone the repo I made available to my computer with the command:
git clone https://github.com/ellyx13/Chatbot-ChatGPT-Python.git
Step 4: Install the necessary python libraries:
pip install -r requirements.txt
Step 5: Open file pyChatbotGPT.py
and paste the cookie code you just saved earlier into the session_token variable.
Step 6: Run the python file with the command:
python pyChatbotGPT.py
It will create a url for you to use on localhost, the default will be the port 7860. You open the url and this is the result.
The principle of operation of this bot is that it will open the chatgpt website with the chrome browser. Submit the content of the question you enter on the chatbot page. Then get the answer on chatgpt that returns the chatbot.
If you want to put the bot on the internet, follow the steps below.
How to put bots on the internet
Step 1: Load ngrok about the machine. Configure token api. You can see the tutorial here.
Step 2: Enter the command: ngrok http 7860
. Ngrok will give you a forwarding url to your local port 7860. You just need to give this link to others to use the bot.
So that’s it then. But this way will have a disadvantage that many people using the bot at the same time will sometimes have errors.
Now no need to log in to chatgpt, just go to your Web site provided by ngrok, you can communicate with ChatGPT. This is also a way for you to share your ChatGPT account without fear of losing your Password.