This is a chatbot based on OpenAI Completion API, implementing agents and function-calling for fact-checking.
It runs as a web app with Flask. It's been tested on DigitalOcean App platform and in a Droplet (server).
This application is mainly developed by Davide Pasca.
See commits for other contributors.
- AI chatbot based on OpenAI and Completion API
- RAG based on LLamaindex and Chroma DB
- Real-time fact-checking using agents
- Sense of time and location using prompt injection
- Web search using function-calling and Brave/DuckDuckGo
- Code syntax highlighting and LaTeX rendering
The main assistant is currently not aware of the fact-checking.
This is a design choice to keep things simple in terms of user experience. Feedback from one AI to another is definitely important, but I'd rather implement (in the future) this kind of back-and-forth self-correction in a thread away from the user.
Fact-checking in web app runs in background, it takes some time to complete, but does not hang the interface.
The web app requires the following environment variables.
Set them in the .env
file for local development and in the app settings for production:
Variable | Description | Required |
---|---|---|
OPENAI_API_KEY |
The API key for OpenAI (get it from the OpenAI dashboard) | Yes |
CHATAI_FLASK_SECRET_KEY |
A random string used by Flask to encrypt cookies e.g. python -c "import os; print(os.urandom(24).hex())" |
Yes |
BRAVE_API_KEY |
The API key for Brave (https://brave.com/search/api/) If there is no Brave API key, the search will default to DuckDuckGo (unreliable) |
Optional |
DO_SPACES_ACCESS_KEY |
The access key for DigitalOcean Spaces | Optional |
DO_SPACES_SECRET_KEY |
The secret key for DigitalOcean Spaces | Optional |
DO_STORAGE_CONTAINER |
The name of the container in DigitalOcean Spaces e.g. myai_spaces |
Optional |
DO_STORAGE_SERVER |
The URL of the DigitalOcean Spaces server e.g. https://myai.sfo.digitaloceanspaces.com |
Optional |
See below on how to set the Digital Ocean storage variables (optional).
Create a DigitalOcean Space and a container for the app.
The storage container name and server URL need to be placed in the environment variables,
both in the .env
file for local development and in the app settings for production.
DO_SPACES_ACCESS_KEY
, DO_SPACES_SECRET_KEY
and DO_STORAGE_CONTAINER
are from
menu API -> Spaces Keys -> Generate New Key
It's suggested to use a virtual environment for Python.
- Install Flask
- Install the dependencies with
pip install -r requirements.txt
- Create a
.env
file in the root directory with the following variables:
OPENAI_API_KEY=********
CHATAI_FLASK_SECRET_KEY=********
BRAVE_API_KEY=********
DO_SPACES_ACCESS_KEY=********
DO_SPACES_SECRET_KEY=********
DO_STORAGE_CONTAINER=********
DO_STORAGE_SERVER=https://********
This is an example for DigitalOcean. Change the steps as needed if you'll be using a different provider, or your own server.
- Created a dedicated Project in DigitalOcean, if required.
- Create an App under the Project.
- The first step of the app creation will ask where to get the code from. You should select this GitHub repository.
- Set the required environment variables in the app (to update them later, go to Manage -> Apps -> Your app name -> Settings -> App-Level Environment Variables).
- Go to the app's Overview page, click on the app name link to go to Component Settings.
- Source Directory: blank (default)
- Run Command:
cd app_web && python app.py
Run with either of the following commands:
(cd app_web && python app.py)
(cd app_web && flask --debug run --host=0.0.0.0 --port=8080)
The app will be available locally at http://127.0.0.1:8080
.
The app will be available globally at https://yourappname.ondigitalocean.app
.
This app implements a RAG system via LLamaIndex. See the directory knowledge
for scripts
on how to build this.
A size optimization script is provided for PDF files for RAG.
This script assumes that images are not relevant.
- Install GhostScript (i.e.
brew install ghostscript
) - Put your knowledge files (currently PDF format) into
knowledge/src
directory. cd knowledge
./optimize_pdfs.sh src _output
- Optimized files will be in
knowledge/_output