Skip to content

ChatGPT with history and customizable prompts in Twilio

License

Notifications You must be signed in to change notification settings

deistermatheus/whatsLLM

Repository files navigation

WhatsLLM

A proof-of-concept integration between Twilio Whatsapp and OpenAI ChatGPT.

Description

Most conversational commerce companies are interested in how new AI developments may improve end user experience. This is a proof of concept project for using WhatsApp as an interface to OpenAI, allowing a customizable prompt and a short-term memory. The project can be modified to include some more elaborate features, such as using embeddings for a custom knowledge base, or integrating with other OpenAI features such as speech to text and image generation.

Getting Started

Prerequisites

Installing

  • Clone this Repository
    git clone https://github.com/deistermatheus/whatsLLM.git
  • Create an environment file, setting appropriate variables for Database, Twilio and OpenAI:
    cp .env.example .env
  • Create the Database Structure
    alembic upgrade head
  • Start the API
   uvicorn project.api.main:app --host 0.0.0.0 --reload
  • Alternatively, to run a local docker image of the project:
    docker build -t whatsllm .
    docker run -it -p 8000:8000 --env-file=./.env whatsllm  bash server.sh
  • Check the OpenAPI docs page or make a direct request to see the project is up and running:
   curl -X 'GET' \
  'http://localhost:8000/health' \
  -H 'accept: application/json'
  • Setup your Twilio Webhook Endpoint

For local development, ngrok is recommended to get a public url for Twilio:

    ngrok http 8000

After obtaining a public URL, set up the Whatsapp Webhook in the Twilio Console. The docs for Twilio Webhooks can be found here.

Deploying

To start the deployment process, a Fly.io account is required:

    fly launch

The app requires a database connection and API keys for integrations, to set required environment variables:

    fly secrets import < .env

After making changes:

    fly deploy

The app should now be available in a public url such as:

    https://<your-chosen-app-name>.fly.dev/health
    https://<your-chosen-app-name>.fly.dev/docs

Deploying Automatically

Create a new secret in the repository with:

    fly tokens create deploy -x 99999h

Setup the GitHub Action by defining a new repository secret with the token

Expected outcome

  • Chat with the bot over Whatsapp, the following capture is using the Twilio Sandbox Number: sample-capture

Mini Roadmap

Features

  • Get the integration working
  • Add SQL Database for short term context
  • Save customizable prompt in chatbot configs
  • Deploy to the cloud
  • Add Telegram as alternative channel
  • Allow more customization choices over GPT (model, temperature...)
  • Voice support
  • Image generation
  • Embeddings for larger context

Code Quality

  • Add Automated Testing with CI Check
  • Improve OpenAPI documentation
  • Improve Type Hinting

License

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

Explore Libraries and Frameworks

Acknowledgments

About

ChatGPT with history and customizable prompts in Twilio

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published