Home technology How to make your own AI chatbot with GPT-3 (world’s most advanced AI)

How to make your own AI chatbot with GPT-3 (world’s most advanced AI)

by satcit

Step 1: Sign up at https://openai.com/api/ and you will receive your own personal API key. We will later enter this key into our algorithm.

Step 2: Install Node Red on your computer or server. I use Node Red on my Contabo VPS server so that the service is available to me 24*7.

Step 3 : Add this node to your Node Red palette.

node-red-contrib-telegrambot ( node-red-contrib-telegrambot (node) – Node-RED )


The simplest method is to go to Manage Palette>Install and search for  node-red-contrib-telegrambot 

Step 4 : Import the below flow to your Node Red

[{"id":"679aeaba.495934","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"71021ca35cde4415","type":"telegram receiver","z":"679aeaba.495934","name":"","bot":"","saveDataDir":"","filterCommands":false,"x":310,"y":640,"wires":[["ee342ba885a7379c"],[]]},{"id":"c1531f7fd0aa46eb","type":"function","z":"679aeaba.495934","name":"prompt","func":"msg.payload = ` The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\\n\\nHuman: Hello, who are you?\\nAI: I am an AI created by OpenAI. How can I help you today?\\nHuman:${msg.payload}\\nAI:`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":640,"wires":[["f57d2d9d9d6bc099"]]},{"id":"f57d2d9d9d6bc099","type":"function","z":"679aeaba.495934","name":"set payload and headers","func":"msg.payload = {\n  \"prompt\": msg.payload,\n  \"temperature\": 0.9,\n  \"max_tokens\": 150,\n  \"top_p\": 1,\n  \"frequency_penalty\": 0.0,\n  \"presence_penalty\": 0.6,\n  \"stop\": [\"\\n\", \" Human:\", \" AI:\"]\n};\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['Authorization'] = 'Bearer YOUR_API_KEY';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":640,"wires":[["ccf78296a8681d9e"]]},{"id":"ccf78296a8681d9e","type":"http request","z":"679aeaba.495934","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.openai.com/v1/engines/davinci/completions ","tls":"","persist":false,"proxy":"","authType":"","x":990,"y":640,"wires":[["e608c69bf5091498","771743e9d7362da6"]]},{"id":"e608c69bf5091498","type":"change","z":"679aeaba.495934","name":"extract text from API response","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.choices[0].text","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":720,"wires":[["dad7b93e3c3a6d1e"]]},{"id":"dad7b93e3c3a6d1e","type":"function","z":"679aeaba.495934","name":"set telegram msg","func":"msg.payload= {\n    chatId: 'YOUR_CHAT_ID',\n    type: 'message',\n    content: msg.payload\n   \n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":720,"wires":[["24dcebed5d6042ca"]]},{"id":"24dcebed5d6042ca","type":"telegram sender","z":"679aeaba.495934","name":"","bot":"","haserroroutput":false,"outputs":1,"x":870,"y":720,"wires":[[]]},{"id":"771743e9d7362da6","type":"debug","z":"679aeaba.495934","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1300,"y":620,"wires":[]},{"id":"ee342ba885a7379c","type":"change","z":"679aeaba.495934","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":560,"wires":[["c1531f7fd0aa46eb"]]}]

The imported flow should look like this.

GPT3

Step 5 : Create a new telegram bot using BotFather on Telegram and enter your bot API token in the telegram bot node. Also in the ‘set telegram message node’, replace YOUR_CHAT_ID with you telegram chat ID. This ID can be obtained from IDBot on telegram.

Step 6 : In the ‘set payload and headers’ node, replace YOUR_API_KEY with your OpenAI API key.

Now you can go to your newly created telegram bot, press ‘start’ and start chatting with GPT-3, the world’s most advanced AI available for public use.

The setup should be up and running now.

photo_2022-01-02_14-39-08

6 comments

Bishop January 2, 2022 - 10:24 pm

Do you replace everything in the single quotes ,’Bearer YOUR_API_KEY’ , with the openAI key or just the “YOU_API_KEY”. I have tried replacing both but don’t seem to get a response from within telegram. The node-red flow does seem to register that it’s seeing requests from my telegram bot when I type to it.

Reply
satcit January 2, 2022 - 5:24 pm

You have to replace YOUR_API_KEY only. ‘Bearer’ should remain there. Here is a screenshot of my setup. For obvious reasons, I have erased part of my API key in the screenshot.
https://flic.kr/p/2mUWkES

Reply
Mason January 30, 2022 - 9:35 am

I am not seeing the telegram bot node to put my bot api token into

Reply
satcit January 31, 2022 - 2:26 pm

Hi.. Double click on either the telegram sender or receiver node and click on ‘Add new telegram bot’. Hope this helps you.

Reply
Mason January 30, 2022 - 10:09 am

Im getting a “message text is empty error in my console”

Reply
Patrick February 11, 2022 - 5:03 pm

Many thanks. I got this working. Worth following node-red tutorial if you have difficulty. One can add a debug node to check each node is working correctly. Am now interesting in modifying this flow by adding speech-to-text and text-to-speech in order to get desktop AI comms working. One can use Watson nodes for this but this is only free for first 1000(?) words/month. However Windows has built in speech-to-text (Windows key + H) so it should be a simple matter to write a program to send this to a file as input to node-red. Can’t get the node-red file watcher to work.

Reply

Leave a Comment