Table of Contents
This is an practical implementation of RAG where you upload the private knowledge base as documents and the LLM will answer based on the private knowledge. It's basically a chat application where user wants to know few things
List of tools/languages the product uses
- Python
- Ollama
- LlamaIndex
- ChromaDB
- Gradio
- Langfuse
Follow the steps below to run the application
- Download Ollama from https://ollama.com and install following the instructions
- Follow instructions to enable ollama cli command
- Run the the following command to pull llama2 7b locally
ollama pull llama2
- Once the model is pulled, run the following command to start running ollama service
ollama serve
*
- Set up a virtual environment using the command
python3 -m venv venv
- Activate the virtual environment using the command
source venv/bin/activate
- Change your IDE settings accordingly to use the created virtual environment
- Install the required dependencies using the command
pip install -r requirements.txt
- We are using pipenv to control the dependency and virtual environment. Install pipenv using the following command
pip install pipenv
- Install the dependencies using the following command
pipenv install
- Change your IDE settings accordingly to use the created virtual environment
- Create a .env file in the root of the project directory
- Refer the .env.example file for the environment variables to be set in the .env
- Follow the below steps to configure langfuse
git clone https://github.com/langfuse/langfuse.git
cd langfuse
docker compose up
- Once it is up and running you can access the observability at
http://localhost:3000
- Create a new user id and password to sign in
- Create a api key from settings and copy the secret key and public key in .env file as shown:
LANGFUSE_SECRET_KEY=sk-<secret_key>
LANGFUSE_PUBLIC_KEY=pk-<public_key>
LANGFUSE_HOST=http://127.0.0.1:3000
- Create a prompt (sample given under samples) from the UI and reference the prompt name in env variable under
PROMPT_TEMPLATE
variable name.
- To prepare the knowledge base create a docs folder in the root of the project directory
- Add pdf documents under the docs folder
To run this from a terminal or command prompt, run the following command
python api.py
python app.py
- To run this as an api, run the following command
python api.py
- Access the application in your browser at
http://localhost:5000
.
To run this from a terminal or command prompt, run the following command
python query_model.py