A chatbot that uses OpenAI's API to reply to incoming text and voice messages from WhatsApp with their GPT3-based language models (Davinci, Ada, Babbage, ...) and to generate images with DALL-E 2.
Requires a valid key to OpenAI's API.
git clone https://github.com/simonsanvil/openai-whatsapp-chatbot
pip install -r requirements.txt
You need to set the OpenAI API key as an environmental variables or add it to a .env file in the working directory where the app will be running:
export OPENAI_API_KEY=[YOUR OPENAI API ACCESS KEY]
/whatsapp/receive
endpoint of this app as its callback url and /whatsapp/status
as its status callback url (follow Twillio's tutorial for instructions about how this is done, should only take a few minutes).export TWILLIO_AUTH_TOKEN=[YOUR TWILIO AUTH TOKEN]
export TWILLIO_ACCOUNT_SID=[YOUR TWILIO ACCOUNT SID]
export FROM_WHATSAPP_NUMBER=[YOUR ASSIGNED TWILIO WHATSAPP NUMBER] #+14155238886
The image below shows which boxes you need to fill in when configuring your Twillio Sandbox for Whatsapp:
export MAX_TOKENS=[NUMBER OF MAX TOKENS IN EACH REPLY]
export CONVERSATION_EXPIRES_MINS=[N MINUTES UNTIL A CONVERSATION IS ERASED FROM MEMORY]
export ALLOWED_PHONE_NUMBERS=[+1234567890,+1987654321] # Default is any number
export START_TEMPLATE=[PATH TO A FILE WITH A TEMPLATE FOR THE START OF A CONVERSATION] #data/start_template.txt
export ASSEMBLYAI_API_KEY=[YOUR ASSEMBLY-AI API KEY]
The ASSEMBLYAI_API_KEY
environmental variable is to use AssemblyAI's API to parse and transcribe the audio of incoming voice messages so that the agent can reply to them. If you don't need or want this, you can ignore that variable.
# (Use --help to see all the options):
python3 -m app.whatsapp
Alternatively the docker container will automatically install all the requirements and run the whatsapp application.
# building the image
docker build -t openai-ws-chatbot .
#running the container
#It is expected that you have all the required environmental variables in a .env file
docker run -p 5000:5000 openai-ws-chatbot --env_file=.env
After following the instructions in the Twilio Sandbox for Whatsapp Tutorial you should be able to join your sandbox and start chatting with the agent inmediately