Code Monkey home page Code Monkey logo

gpt-for-whatsapp's Introduction

GPT-4 / GPT-3 for Whatsapp

Deploy

GPT for Whatsapp is an open-source project that integrates OpenAI GPT-3 and GPT-4 with WhatsApp using the Twilio API. This project allows users to chat with an AI agent through WhatsApp, making it easy for them to get instant responses and assistance.

Features

  • Connects with OpenAI GPT-3 and GPT-4 models
  • Supports WhatsApp messaging through the Twilio API
  • Stores data reply in PostgreSQL database
  • Uses Flask for serving API endpoints
  • Integrates with Pinecone for extended memory

Prerequisites

  • Python 3.10+
  • PostgreSQL
  • A Twilio account (demo account or with a verified WhatsApp number)
  • OpenAI API key
  • Pinecone API key

Installation and Configuration

  1. Create a virtual environment and activate it:

python3 -m venv venv source venv/bin/activate

  1. Install the required packages:

pip install -r requirements.txt

  1. Set up your environment variables by copying .env.template to .env:

cp .env.template .env

  1. Open the .env file and fill in the required information:
AI_AGENT_NAME=<Your AI Agent Name>
AI_AGENT_ROLE=<Description of the AI Agent's role and company>

## OPENAI LLM
OPENAI_API_KEY=<Your OpenAI API Key>
OPENAI_CHAT_MODEL=gpt-3.5-turbo # or gpt-4, if available
OPENAI_CHAT_TOKEN_LIMIT=4000

## Pinecone Credentials
PINECONE_API_KEY=<Your Pinecone API Key>
PINECONE_API_ENVIRONMENT=<Your Pinecone Environment>
PINECONE_POD_TYPE=p1
PINECONE_TABLE_NAME=gpt-twilio # update if needed

## Twilio Credentials
TWILIO_ACCOUNT_SID=<Your Twilio Account SID>
TWILIO_ACCOUNT_TOKEN=<Your Twilio Account Token>
TWILIO_WHATSAPP_NUMBER=whatsapp:+<Your Verified WhatsApp Number>

## PostgreSQL Database
DATABASE_URL=<Your PostgreSQL Connection String>
  1. Run the application:

flask run

  1. The server will start running at http://localhost:5000. You can now use the AI-WhatsApp Assistant by sending a message to your Twilio WhatsApp number.

Configuring Twilio Account

To set up a free Twilio account and configure it for the AI-WhatsApp Assistant, follow these steps:

  1. Sign up for a free Twilio account at https://www.twilio.com/try-twilio.
  2. Once your account is created and you're logged in, navigate to the Twilio Console.
  3. Configure the whatsapp API on Develop > Messaging > Try it out > Send a Whatsapp Message
  4. Go to the 'Sandbox Settings' section and configure the webhook for incoming messages. This repo will provide https://yourserver.com/chat and https://yourserver.com/status_check to use as webhook.
  5. Save the changes by clicking on the 'Save' button at the bottom of the page.
  6. In the Twilio Console, navigate to the 'Settings' > 'WhatsApp Sandbox' section.
  7. Follow the instructions to link your WhatsApp account to the Twilio Sandbox. Send the provided code from your WhatsApp account to the Twilio Sandbox number.
  8. Once your WhatsApp number is linked to the Twilio Sandbox, you can use it to send messages to the AI WhatsApp Assistant.
  9. Don't forget to update the .env file in your project with your Twilio Account SID, Account Token, and WhatsApp number.

Postgres and Pinecone

This project uses postgreSQL to store the user's message and AI replies to retrieve the last 10 message to include in the context of the chat. Also use these messages to retrieve relevant history from Pinecone.

Since pinecone we can't retrieve messages based on datetime, postgreSQL seem a good option for that

This will give support for long history

Contributing

Please feel free to submit issues and pull requests for bug fixes or new features. Make sure to follow the code style and include tests where necessary.

License

This project is licensed under the MIT License - see the LICENSE file for details.


gpt-for-whatsapp's People

Contributors

jasielmacedo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.