Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/labrijisaad/llm-rag
A Streamlit app leveraging a RAG LLM with FAISS to offer answers from uploaded files.
https://github.com/labrijisaad/llm-rag
chatgpt cicd embedding-vectors faiss llm machine-learning mlops openai rag rag-llm streamlit streamlit-webapp
Last synced: 10 days ago
JSON representation
A Streamlit app leveraging a RAG LLM with FAISS to offer answers from uploaded files.
- Host: GitHub
- URL: https://github.com/labrijisaad/llm-rag
- Owner: labrijisaad
- Created: 2024-04-01T11:16:10.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-13T14:25:38.000Z (7 months ago)
- Last Synced: 2024-04-14T04:29:15.070Z (7 months ago)
- Topics: chatgpt, cicd, embedding-vectors, faiss, llm, machine-learning, mlops, openai, rag, rag-llm, streamlit, streamlit-webapp
- Language: Jupyter Notebook
- Homepage:
- Size: 1.31 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `LLM RAG` - Streamlit RAG Language Model App π€
## π Overview
This Streamlit app leverages Retrieval-Augmented Generation (RAG) by using OpenAI's Large Language Model (LLM) in conjunction with FAISS, a vector database. The app allows users to upload markdown files π, ask questions related to the content of these files β, and receive AI-generated answers based on the uploaded content π.## β How It Works
The LLM RAG Streamlit app is structured into several key areas, each serving a specific function within the application:
- **Setup Knowledge Base** π: Upload markdown documents to establish the knowledge base.
- **Explore Knowledge Base** π: Browse and manage the uploaded documents.
- **RAG Query** π‘: Pose questions to receive answers referencing the knowledge base and the model's knowledge.Additionally, the app offers advanced settings for customization based on user needs:
- **OpenAI Embedding Model Settings**: Select the embedding model for document vectorization.
- **OpenAI LLM Settings**: Choose the OpenAI language model variant for generating answers.
- **LLM Temperature**: Adjust the creativity of the modelβs responses.
- **Max Completion Tokens**: Define the maximum length of the generated response.
- **Drop All Documents in Knowledge Base**: Clear the database by typing a confirmatory command.## π οΈ System Architecture
The following diagram illustrates the flow of data through the system:```mermaid
graph TD
A[Markdown Documents] -->|Data Cleaning &
Splitting in Chunks| B[Cleaned Text]
B -->|OpenAI Model
Embedding| C[Document Embeddings]
C -->|Store| D[(Vectorstore)]
D -->|Similarity Search| E[Relevant Documents]
F[User Question] -->|OpenAI Model
Embedding| G[Query Embedding]
G -->|Fetch| D
F --> J[Contextualized Prompt]
E --> J
J -->|OpenAI LLM Model| L[Answer]
subgraph Data Preparation
A
B
end
subgraph Vectorization
C
G
end
subgraph Relevant Documents Retrieval
D
E
end
subgraph LLM Querying
J
L
end
%% Styles
style A fill:#7f7f7f,stroke:#fff,stroke-width:2px
style B fill:#8fa1b3,stroke:#fff,stroke-width:2px
style C fill:#8fa1b3,stroke:#fff,stroke-width:2px
style D fill:#8fa1b3,stroke:#fff,stroke-width:2px
style E fill:#8fa1b3,stroke:#fff,stroke-width:2px
style F fill:#7f7f7f,stroke:#fff,stroke-width:2px
style G fill:#8fa1b3,stroke:#fff,stroke-width:2px
style J fill:#e07b53,stroke:#fff,stroke-width:2px
style L fill:#e07b53,stroke:#fff,stroke-width:2px
```## Project Structure ποΈ
The project's main directories are laid out as follows:```
LLM-RAG/
βββ .github/workflows/ # CI/CD pipeline definitions
βββ configs/ # Configuration files for the model (model names, pricing..)
βββ data/ # Data and indices used by the app (FAISS Knowledge Base)
βββ docker/ # Docker related files
βββ notebooks/ # Jupyter notebooks for experiments
βββ secrets/ # API keys and other secrets (excluded from version control)
βββ src/ # Source code for the LLM RAG logic
βββ streamlit_app/ # Streamlit app files for the Web Interface
βββ tests/ # Test cases for the application
βββ .dockerignore # Specifies ignored files in Docker builds
βββ .gitignore # Specifies untracked files ignored by git
βββ Dockerfile # Dockerfile for building the Docker image
βββ Makefile # Make commands for building and running the app π§βπ»
βββ README.md # Documentation and instructions
βββ requirements.txt # Python dependencies for the project
βββ (additional project files and scripts)
```## π Getting Started
To begin using the LLM RAG app, follow these simple steps:
1. **Clone the Repository:**
```
git clone https://github.com/labrijisaad/LLM-RAG.git
```2. **Create the Environment:**
Set up your virtual environment using either venv or conda:
```
# Using venv
python -m venv env_llm_rag
source env_llm_rag/bin/activate
# Using conda
conda create --name env_llm_rag
conda activate env_llm_rag
```3. **Install Dependencies:**
Install the required dependencies byrunning:
```
pip install -r requirements.txt
```4. **Set Up OpenAI API:**
Rename the example credentials file to `secrets/credentials.yml` and replace the placeholder key ('sk-xxx') with your actual OpenAI API key. You can obtain your API key by following the instructions provided in the [OpenAI documentation](https://platform.openai.com/docs/quickstart?context=python).
```
rename secrets/credentials-example.yml secrets/credentials.yml
```5. **Run the Streamlit App:**
Launch the Streamlit app using either the provided Makefile command or directly via the Streamlit CLI:
```
# Using Makefile
make stream
# Or directly
streamlit run streamlit_app/main.py
```
## π³ Docker VersionThe application is available as a Docker container and can be easily set up and run with a few commands. If you want to run the application using the Docker image from the public registry, ensure that you have a `secrets` directory with the necessary API keys as specified in the `secrets/credentials.yml`.
To pull and run the Docker container:
1. **Pull the Docker Image:**
You can pull the image directly from **Google Artifact Registry** using the following command:
```shell
docker pull europe-west1-docker.pkg.dev/llm-rag-application/llm-rag/llm_rag_app:latest
```2. **Run the Docker Container:**
After pulling the image, you can run it with:
```shell
docker run -p 8501:8501 -v $(pwd)/secrets:/app/secrets europe-west1-docker.pkg.dev/llm-rag-application/llm-rag/llm_rag_app:latest
```
This command will start the container and mount your **`secrets`** directory for the application to use.If you prefer to use the **Makefile**, the equivalent commands are provided for convenience:
```shell
# To pull the Docker image
make docker-pull# To run the pulled Docker image
make docker-run-pulled
```The Streamlit app will be available at **`http://localhost:8501`** once the container is running.
## π Connect with me