A Python Flask web app template for doing AI Question and Answering with sources using Langchain. Optimized for minimal developer setup by running in a Docker container, and provides a framework for adding and embedding documents. Already contains several embedded documents preloaded and more can be added easily using a script.
-
To get started, clone this repository.
git clone https://github.com/pgrennin/ai_question_answer_web_template.git
-
Add your OPENAI API KEY to app/config/config.py
-
Run the following command to build the Docker image and run the container. (This script requires Docker. Please install if you don't have it already.)
bash run.dev.sh
-
Go to http://localhost:8000/ to see the application and run questions and answers on one of the documents already pre-created.
Create embeddings on a document of your choice by doing the following:
- Create a
.txt
file and place in the app/assets/raw directory.
example:
curl https://www.gutenberg.org/cache/epub/3755/pg3755.txt -o app/assets/raw/thomas_paine_common_sense.txt
- Run the create embeddings script
bash create_embeddings.sh
What this script does. This will create new embeddings for all files in app/assets/raw. If an embedding file has already been created for a file, it will not be recreated. It checks if embedding was already created in /app/assets/embeddings.
- Go to http://localhost:8000/ view your document and ask questions on it.
- Please feel free to open a PR if you have any suggestions or improvements.
- Only tested with txt documents but could be extended to other file types.
- Errors may occur uploading very large documents.
- After starting this project I found Langchain has already created something similar with a chatbot template. (https://blog.langchain.dev/langchain-chat/)
- Python 3.11
- LangChain
- Flask
- OpenAI API
- FAISS
- Docker
- Bootstrap