βοΈ Indian LAW AI-Agent
This AI ChatBot is designed to be
private
and can answer your queries on Indian Constitution & Indian Penal Code (IPC). This app is using Google ADK for the frontend &
LiteLlm
wrapper which is build with
Ollama
LLMs which are namely
llama3.2
&
mxbai-embed-large
.
π½οΈ Demo
You can play below Video or click this
Youtube Link
to see the demo. Please let me know in the comments, how do you feel about this App.
π§ Our Scematic Architecture
This is the scematic flow
diagram
β οΈ Disclaimer
This AI application is creating its own
RAG
database based on two markdown files:
Indian Constitution
&
Bharatiya Nyaya Sanhita (IPC)
locaded
here
. This markdown files were generated using the
docling project
from the PDF files which are publicly available. The author is not responsible for any wrong information given by this AI Agent.
π¦ Quickstart Guide
You can run it on
Google Colab
and you can run it on a
Free
GPU machine with the available
code
. If you want to deploy this complete application on the Container World like Docker, Kubernetes etc. you may follow the next steps.
π Code Link
Here is the full codebase on GitHub
π Run it on Google Colab
You can access
Google Colab
for free if you have a Google/Gmail account.
You can download the
code
& run it or you can directly open it with below option.
βΈοΈ Run it on Kubernetes (example is on GKE)
The example is on GKE, but you can replicate it on any K8S environment. You need to change (or remove) some parameters
tolerations
,
gke-accelerator
,
gke-spot
etc. in the YML files in
k8s
directory.
-
Get the
kubectlsetup for your GKE cluster (only for GKE) -
Run the
Ollamabackend -
Run
litellmapp -
Deploy the UI on K8S
-
Then get your Load balancer IP address & access it from your browser. Optionally you can map it with your domain.
π Run using docker
-
Run the
Ollamabackend on a container and make sure nvidia-container-toolkit is installed if you have Nvidia GPU. The below image will automatically download the required models during startup which may take some time to be ready, depending on internet speed.docker pull sdas92/ollama-llama3.2-mxbai-embed:v1 # check for the latest version at docker hub # for GPU machines docker run -d --gpus=all -p 11434:11434 --name ollama sdas92/ollama-llama3.2-mxbai-embed:v1 # for CPU only machines docker run -d -p 11434:11434 --name ollama sdas92/ollama-llama3.2-mxbai-embed:v1 -
Run the
LiteLlmbackend (which can also be accessed via API calls). In the Ollama URL, use the container IP, do not uselocalhostas it will try access the ollama within litellm containerdocker pull sdas92/law-litellm:v1 docker run -d -p 4000:4000 -e OLLAMA_API_BASE="http://your-ollama-host:11434" --name litellm-rag sdas92/law-litellm:v1 # use the container IP # You can test or use the API direcly with your application, sample format curl -X POST http://localhost:4000/chat/completions -H 'Content-Type: application/json' -H 'Authorization: Bearer sk-1234' -d '{"model": "indian-law-llm", "messages": [{"role": "user", "content": "Punishment for money fraud?"}]}' -
Run the UI & again use the contair IP
litellm-ragin the OpenAI host URL insread oflocalhost -
Open your browser & type
http://localhost:8000to chat with the AI Model.
βοΈ Manual execution on local system or Development / Update
Prerequisites
Run Ollama Backend
- Install Ollama on your system from the official website
- Then Pull the required models
Backend Service
Use the backend service in separate terminal than the frontend
Set ENV vars
Run the backend service in separate terminal
cd ./backend/markDownRAG/
python -m venv .venv
source .venv/bin/activate # use .\venv\Scripts\activate on windows
pip install -r requirements.txt
# run the litellm service
litellm --config config.yaml
Frontend Service
Run frontend in another terminal
Set ENV vars
export OPENAI_API_KEY="your-key" # create your key from litellm or use default 'sk-1234'
export OPENAI_BASE_URL="http://localhost:4000"
Run the frontend service
cd ./frontned
python -m venv .venv
source .venv/bin/activate # use .\venv\Scripts\activate on windows
pip install -r requirements.txt
# run the uvicorn service for ADK
sh -c "uvicorn main:app --host 0.0.0.0 --port 8000" # access the UI at localhost:8000
Access the UI
Open browser & type
http://localhost:8000
π Building the docker images & push
You may create your own images & store in your repo
Ollama backend
cd ./backend/ollama/
export APP_VERSION="v1"
export IMAGE_URI="sdas92/ollama-llama3.2-mxbai-embed:${APP_VERSION}" # change to your repo URI
docker build -t ${IMAGE_URI} .
docker push "${IMAGE_URI}"
LiteLlm backend
cd ./backend/markDownRAG/
export APP_VERSION="v1"
export IMAGE_URI="sdas92/law-litellm:${APP_VERSION}" # change to your repo URI
docker build -t ${IMAGE_URI} .
docker push "${IMAGE_URI}"