Simple Flask app to serve as a proxy for LLMs like Ollama, with Bearer authentication.
294
This is a simple Flask application designed to serve as a proxy for Large Language Models (LLMs) like Ollama, while enforcing Bearer authentication. The proxy forwards requests to the underlying LLM API and streams the response back to the client.
Table of Contents
To run this proxy, you'll need:
git clone [email protected]:luisgreen/llm_proxy_auth.gitpip install -r requirements.txt in the project directoryexport LLM_API_URL='https://your-llm-api-url.com/api'
export REQUIRED_BEARER_TOKEN='your-bearer-token'
python proxy.py in the project directoryDockerfile, which you can use to create a Docker image for this proxy. To build and run it, first make sure that you have Docker installed on your machine.docker build -t ollama-proxy in the project directory to create a Docker imageTo run the proxy with Docker Compose, create a new file named docker-compose.yml with the following contents:
version: '3'
services:
ollama-proxy:
build: .
environment:
LLM_API_URL: ${LLM_API_URL}
REQUIRED_BEARER_TOKEN: ${REQUIRED_BEARER_TOKEN}
ports:
- "5000:5000"
depends_on:
- llm-api
In this example, we're assuming you have a separate service for the LLM API. If that's not the case, simply remove the llm-api reference.
To run the proxy with Docker Compose:
export LLM_API_URL='https://your-llm-api-url.com/api'
export REQUIRED_BEARER_TOKEN='your-bearer-token'
docker-compose up in the project directory to start the proxyNow you can access the proxy at http://localhost:5000. The proxy will forward requests to your LLM API, enforcing Bearer authentication along the way.
Note that this is just a basic example, and you may want to modify the Docker Compose file to fit your specific use case.
Content type
Image
Digest
sha256:d1e266572…
Size
22.6 MB
Last updated
almost 2 years ago
docker pull luisgreen/llm_proxy_auth