Giter VIP home page Giter VIP logo

myopenaiwts's Introduction

WhatApp OpenAI-API Chatbot

Build and deploy Python app to Azure Web App - openai-chatbot

Open In Colab

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.

Installation

git clone https://github.com/simonsanvil/openai-whatsapp-chatbot
pip install -r requirements.txt

Requirements

Setup and Configuration

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]

To run the Whatsapp chatbot:

  • Have a Twillio account and setup a Twilio for Whatsapp messages sandbox with the /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).
  • Set the following environmental variables: (or add them to the same .env file as the one with the api key).
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:

Additional config:

  • Other environmental variables can be set to control the default parameters of the agent (see agent.py for more details), control configurations of the app, or activate specific features:
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]
  • It is also enough to have these variables in a .env file in the working directory where the app is running.

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.

Running the app

Run from the command line:

# (Use --help to see all the options):
python3 -m app.whatsapp

Run with Docker:

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

Usage

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


myopenaiwts's People

Contributors

simonsanvil avatar dependabot[bot] 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.