A starter project to create a chat application using ChatGPT, Flask, and Auth0.
- create and activate a virtual environment. I recommend using
pyenvwith thepyenv-virtualenvplugin. - Install the requirements using
pip install requirements - Set up API Keys
- Change the default prompt in
components/chat.pyif you wish - Run the app using
python server.py
Auth0 makes managing multiple social logins easy.
- Go to Auth0.com and make an account
- Go to
Applicationsand chooseCreate Application - Create a regular web application

- Make a
.envfile with the following values:
AUTH0_CLIENT_ID=<YOUR_CLIENT_ID>
AUTH0_CLIENT_SECRET=<YOUR_CLIENT_SECRET>
AUTH0_DOMAIN=<YOUR_AUTH0_DOMAIN>
These values will be explicitly loaded by us in our code. Look for env.get(...) calls.
- Under
Application URIs, addhttp://localhost:3000/callbacktoAllowed Callback URLs - In the same section, add
http://localhost:3000/welcometoAllowed Logout URLs - You will have to change those values accordingly if you deploy the app somewhere other than
http://localhost:3000
- Make an account with OpenAI
- Create a new API key and add it to the
.envfile
OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
This value will be implictly loaded by the openai library.
Authentication in this app is done using jwt which are signed cookies containing the user identity. The jwt cookie is a bearer token, meaning that if someone else has that token, they can impersonate your user. If you use this app in the real world, you will need https to secure client-server communications so the cookie can't be intercepted. When you do enable https, you should also set SESSION_COOKIE_SECURE=True for flask.
The other half of this is that your users jwt is signed by flask, which means flask needs a secret key. If someone can guess your secret key, they can make their own user tokens. By default, the SECRET_KEY is None. You can add a secret key of your choice to the .env file:
APP_SECRET_KEY=<YOUR_SUPER_SECRET_KEY>
These values will be explicitly loaded by us in our code. Look for env.get(...) calls.
It might be a good idea to use a specialized tool to generate a random key.
