Status: [UNTESTED] Endpoints found: https://localhost:8443/v1/chat/completions Source: https://github.com/faramarz-fakhri/granite-guardian-proxy # IBM Granite Guardian Reverse Proxy Exercise This project demonstrates a reverse proxy to OpenAI with safety inspection and blocking. ## Project Structure client/ Demo OpenAI-compatible client mitmproxy/ mitmproxy addon for request/response inspection and blocking nginx/ TLS termination and reverse proxy configuration scripts/ Local certificate generation utilities ## Architecture ```text Python client -> HTTPS https://localhost:8443/v1/chat/completions -> NGINX terminates SSL with a locally trusted certificate -> mitmproxy reverse proxy inspects request/response bodies -> OpenAI API ``` ## What is implemented - Step 1: `client/client.py` sends a prompt to OpenAI and prints the response. - Step 2: `mitmproxy/guardian_addon.py` intercepts OpenAI calls. - NGINX terminates TLS. - The client verifies TLS using the generated local CA certificate. - Prompts and responses are inspected. - Blocking reasons: 1. Description of violent acts 2. Inquiries on how to perform an illegal activity 3. Any sexual content 4. If none of those simple categories match but Guardian score is over the threshold, the response says the prompt is considered toxic. ## Requirements - Docker and Docker Compose - OpenSSL - Python 3.10+ - An OpenAI API key - For vLLM, a machine with enough resources for the selected Granite Guardian model. GPU is recommended. ## Runtime Modes ## Setup ```bash cp .env.example .env # edit .env and set OPENAI_API_KEY ./scripts/generate-certs.sh ``` Start the proxy stack: ```bash docker compose up --build ``` In another terminal, create a local Python environment for the demo client: ```bash cd client python -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` Export the API key and CA bundle: ```bash export OPENAI_API_KEY="sk-your-openai-key" export SSL_CERT_FILE="$(pwd)/../nginx/certs/ca.crt" export REQUESTS_CA_BUNDLE="$(pwd)/../nginx/certs/ca.crt" ``` ## Run through the proxy ```bash python client