This sample demonstrates how to deploy a Flask-based Retrieval-Augmented Generation (RAG) chatbot using OpenAI's GPT model. The chatbot retrieves relevant documents from a knowledge base using scikit-learn and Sentence Transformers and then generates responses using OpenAI's GPT model.
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional - for local development) Docker CLI
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
- Clone the repository.
- Create a
.env
file in the root directory and set your OpenAI API key or add the OPENAI_API_KEY into your .zshrc or .bashrc file: - Run the command
docker compose -f compose.dev.yaml up --build
to spin up a docker container for this RAG chatbot
- The knowledge base is the all the markdown files in the defang docs website. The logic for parsing can be found in './app/get_knowledge_base.py'.
- The file
get_knowledge_base.py
parses every webpage as specified into paragraphs and writes toknowledge_base.json
for the RAG retrieval. - To obtain your own knowledge base, please feel free to implement your own parsing scheme.
- for local development, please use the compose.dev.yaml file where as for production, please use the compose.yaml.
Title: Scikit RAG + OpenAI
Description: An application demonstrating a GPT-4-based chatbot enhanced with a Retrieval-Augmented Generation (RAG) framework, leveraging scikit-learn for efficient contextual embeddings and dynamic knowledge retrieval.
Tags: Flask, Scikit, Python, RAG, OpenAI, GPT, Machine Learning
Languages: python