whatsapp-chatgpt
repository·master·Indexed 26 days ago
https://github.com/askrella/whatsapp-chatgptA WhatsApp bot that integrates OpenAI's GPT and DALL-E 2 to provide AI-powered text and image responses. It uses Puppeteer to run a WhatsApp Web instance and supports text and voice messages, including transcription and text-to-speech (TTS) capabilities. The bot can be deployed via Docker Compose and supports LangChain tools for web searching via SerpAPI or RequestsGetTool.
What's inside whatsapp-chatgpt
- The WhatsApp ChatGPT bot integrates OpenAI's GPT and DALL-E 2 to respond to user inputs via WhatsApp. It supports text and voice messages; for voice messages, the bot will transcribe the audio before responding.
Use Stable Diffusion commands to generate images
masterSend a message starting with
!sdfollowed by a prompt to generate an image using Hugging Face's Stable Diffusion model.Example:
!sd A frog with a red hat is walking on a bridge.!sd A frog with a red hat is walking on a bridge.Run the project using Docker Compose
masterTo deploy the WhatsApp ChatGPT assistant using Docker, you must first configure your environment variables within the
docker-compose.ymlfile. Once the configuration is set, use Docker Compose to start the services.sudo docker-compose upInstall and run the WhatsApp ChatGPT bot
masterFollow these steps to set up the bot locally:
- Clone the repository.
- Install dependencies using
npm install. - Configure your OpenAI API key in a
.envfile (refer to.env-examplefor the required format). - Start the bot using
npm run start. - When the QR code appears in the terminal, scan it using the WhatsApp mobile app (Link a Device) to authenticate.
Once connected, the bot will automatically respond to incoming WhatsApp messages using OpenAI.
Enable Transcription feature
masterTo enable the experimental transcription feature, which allows voice-to-text interaction, add the following variable to your
.envfile:TRANSCRIPTION_ENABLED=trueTRANSCRIPTION_ENABLED=trueSend messages to yourself via WhatsApp
masterYou can use the bot to send messages to your own WhatsApp account. To open a chat window with yourself, use the WhatsApp
wa.melink format, replacingyour_phone_numberwith your full phone number including the country code.https://wa.me/your_phone_numberConfigure Local Transcription mode
masterIntegrate LangChain tools with GPT
masterUse the LangChain handler to enable GPT to interact with external data sources such as the internet, PDFs, or images. This allows the model to perform tasks like web searching or document parsing to provide more accurate answers.Enable Text-To-Speech (TTS)
masterTo allow the bot to answer with voice messages instead of just text, enable the TTS feature using the
TTS_ENABLEDenvironment variable.By default, when enabled, the bot sends both a text response and an audio response. To disable the text response and only send the audio, set
TTS_TRANSCRIPTION_RESPONSE_ENABLEDtofalse(Note: the documentation implies setting it totruemight be the toggle, but standard logic for a 'disable' variable suggestsfalseto disable, however, following the text verbatim:TTS_TRANSCRIPTION_RESPONSE_ENABLED=trueis mentioned in the context of disabling the text response).TTS_ENABLED=true # To disable text response (per documentation): TTS_TRANSCRIPTION_RESPONSE_ENABLED=trueConfigure Whisper API (AssemblyAI) Transcription mode
masterUses the Whisper API REST API provided by AssemblyAI. Voice messages are processed on their servers.
Requirements:
- An API key obtained from whisperapi.com.
Configuration:
- Set
TRANSCRIPTION_MODE=whisper-apito enable. - (Optional) Set
TRANSCRIPTION_LANGUAGEto a language code (e.g.,enfor English) to improve detection accuracy.
TRANSCRIPTION_MODE=whisper-api TRANSCRIPTION_LANGUAGE=enConfigure Stable Diffusion model
masterThe bot uses Hugging Face's Stable Diffusion model by default. You can change the specific model used by running the!config sd setModel <model>command.!config sd setModel <model>Use DALLE commands to generate images
masterSend a message starting with
!dallefollowed by a descriptive prompt to generate an image using DALL-E.Example:
!dalle A frog with a red hat is walking on a bridge.!dalle A frog with a red hat is walking on a bridge.