This is the documentation for the SelfGPT WhatsApp bot.
This bot allows you to contact GPT3 directly from WhatsApp.
This bot also allows you to save your own personal data and later search and retrieve it using GPT3 to generate a response. In the examples
folder you can see several examples of how to use this bot so you don't have to remember anything ever again.
Note: While the code in its current state is very useful I would highly appreciate any contributions that would make it more "production-ready".
The bot can be used in two ways:
- No-Command: This is the default mode. The bot will respond to any message you send it through the GPT3 regular completion API.
- Commands: This mode is activated by sending the bot a message starting with the command character. The default command character is
/
.- Currently supported commands:
/h
: Show a help message that lists all the commands/s <message>
: Save the message to the database/q <question>
: Ask a question about the database and get a response from GPT3/f <message>
: Find related messages in the database
- Currently supported commands:
- Add a way to delete messages from the database.
- Add a way to edit messages in the database.
- Receive PDF/Word files and parse them into the database.
- Receive audio messages, transcribe them (using OpenAI Whisper or something similiar) and parse them into the database.
- Add ability to upload photos, embedd them with OpenAI CLIP and enable searching them with natural language.
-
Clone or download the code from the repository.
-
Install the requirements using
pip install -r requirements.txt
-
Set an account on OpenAI and get your API key.
-
Add the API key to the
config.yaml
file. -
Choose the path for your database file and add it to the
config.yaml
file as well. -
Twilio:
- Set an account on Twilio.
- Go to Twilio's whatsapp website and sign up.
- Connect Twilio with WhatsApp (see here for a tutorial).
- Save the contact details given by Twilio.
- Send message to the number given by Twilio as instructed in the tutorial.
-
NGROK
- Download and install NGROK.
- Open the terminal and run
ngrok http 5000
(5000 is the default port used by Flask). - From that Ngrok links, copy the HTTPS link URL
- Go to back to Twilio's sand box for whatsapp and add the URL given by NGROK with the suffix /wasms to the box marked
WHEN A MESSAGE COMES IN
(see here for a tutorial) and press save.
That's it! You can now use the bot by running selfgpt.py
. Notice that tha bot runs only as long as the program runs.
- The Twilio account disconnects every 72 hours: Reconnecting is easy. Just send the same message you sent on step 6 that connected you in the first place.
- The Ngrok changes URL: Sometime the bot would stop responding. This can be caused by the Ngrok changing the URL. In this case you have to repeat step 7.
This is an open source project and contributions are welcome. If you want to contribute, you can do so by forking the repository and making a pull request. If you have any questions or suggestions, you can open an issue or contact me directly.
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details
Huge credit for Pragnakalp for making this great tutorial on how to create a WhatsApp bot using Twilio and Flask. I used his tutorial as a base for this project. You can find the tutorial here.