Compare commits
18
Commits
dd8f69ecb6
..
0.9.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25f19b6ada | ||
|
|
5b97ed0ef7 | ||
|
|
222b204d4b | ||
|
|
9910e6e062 | ||
|
|
6e704da86b | ||
|
|
bd0dc0478f | ||
|
|
92fd66381f | ||
|
|
c46c1c2b12 | ||
|
|
d243523906 | ||
|
|
2319434b0f | ||
|
|
7912431ffb | ||
|
|
114c45dc7e | ||
|
|
6f67f29f68 | ||
|
|
3b7c88bf2c | ||
|
|
03712fe401 | ||
|
|
a0512b3b2b | ||
|
|
511e85ea79 | ||
|
|
cdaec894d8 |
No files matched your search
+45
-6
@@ -1,11 +1,50 @@
|
|||||||
.git/
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
.venv/
|
.venv/
|
||||||
venv/
|
venv/
|
||||||
|
*.egg-info/
|
||||||
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
backend/tests/
|
||||||
|
|
||||||
|
# Environment & secrets
|
||||||
.env
|
.env
|
||||||
|
*.env.local
|
||||||
|
|
||||||
|
# Databases
|
||||||
|
*.db
|
||||||
|
*.sqlite3
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs/
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# IDE & tools
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
.claude/
|
||||||
|
|
||||||
|
# Git
|
||||||
|
.git/
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Frontend
|
||||||
frontend/node_modules/
|
frontend/node_modules/
|
||||||
frontend/dist/
|
frontend/dist/
|
||||||
backend/__pycache__/
|
|
||||||
backend/**/__pycache__/
|
# Docker
|
||||||
backend/*.pyc
|
docker-compose.yml
|
||||||
backend/test.db
|
.dockerignore
|
||||||
backend/tests/
|
|
||||||
|
# Docs
|
||||||
|
*.md
|
||||||
|
|
||||||
|
# Dev & build scripts
|
||||||
|
run_dev.py
|
||||||
|
build_push.sh
|
||||||
|
start.sh
|
||||||
|
test_api.sh
|
||||||
+5
-1
@@ -14,7 +14,11 @@ __pycache__/
|
|||||||
*.sqlite3
|
*.sqlite3
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
.idea/
|
.idea/*
|
||||||
|
!.idea/runConfigurations/
|
||||||
|
.idea/runConfigurations/*
|
||||||
|
!.idea/runConfigurations/Dev.xml
|
||||||
|
!.idea/runConfigurations/Docker_Push.xml
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
# Frontend build
|
# Frontend build
|
||||||
|
|||||||
Generated
+16
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Dev" type="PythonConfigurationType" factoryName="Python">
|
||||||
|
<module name="llm_quota" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="IS_MODULE_SDK" value="false" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/run_dev.py" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Docker Push" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/build_push.sh" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="/bin/bash" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
+217
@@ -0,0 +1,217 @@
|
|||||||
|
# mediaeng/llmproxy
|
||||||
|
|
||||||
|
A lightweight reverse proxy for [Ollama](https://ollama.com) that manages API keys with configurable token and request quotas. Incoming requests in OpenAI-compatible format are authenticated, checked against the quota, and forwarded to the configured Ollama server.
|
||||||
|
|
||||||
|
Ollama does not need to run on the same host — `OLLAMA_URL` can point to any reachable server: the Docker host itself, another machine on the network, or a remote server.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- OpenAI-compatible endpoint (`/v1/chat/completions`, `/v1/models`)
|
||||||
|
- API key management with daily and monthly token/request limits
|
||||||
|
- Web-based admin interface (port 8001)
|
||||||
|
- Streaming support (Server-Sent Events)
|
||||||
|
- Tool use / function calling passthrough
|
||||||
|
- Rotating usage logs
|
||||||
|
- SQLite (default) or PostgreSQL
|
||||||
|
|
||||||
|
## Ports
|
||||||
|
|
||||||
|
| Port | Service |
|
||||||
|
|------|---------|
|
||||||
|
| `8000` | Proxy endpoint (OpenAI API) |
|
||||||
|
| `8001` | Admin API + web interface |
|
||||||
|
|
||||||
|
Port 8001 must be exposed because the container serves the admin interface directly on this port. To restrict access to the local machine, bind it to `127.0.0.1` — this makes the port reachable only from the host, not from the network:
|
||||||
|
|
||||||
|
```
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `ADMIN_PASSWORD` | – | **Required.** Password for the admin interface |
|
||||||
|
| `OLLAMA_URL` | `http://localhost:11434` | URL of the Ollama server (without `/v1` suffix) |
|
||||||
|
| `DEFAULT_MODEL` | `llama3` | Model used when the client does not specify one |
|
||||||
|
| `DATABASE_URL` | `sqlite:///./test.db` | Database connection string (SQLite or PostgreSQL) |
|
||||||
|
| `PROXY_HOST` | `0.0.0.0` | Proxy bind address |
|
||||||
|
| `PROXY_PORT` | `8000` | Proxy port |
|
||||||
|
| `ADMIN_PORT` | `8001` | Admin API port |
|
||||||
|
| `APP_TZ` | `Europe/Berlin` | Timezone for daily/monthly quota resets |
|
||||||
|
| `LOG_FILE` | `logs/usage.log` | Path of the rotating usage log file |
|
||||||
|
|
||||||
|
## Docker Compose – External Ollama, SQLite
|
||||||
|
|
||||||
|
Use this when Ollama runs outside of Docker — on the Docker host or any other reachable server. Adjust `OLLAMA_URL` accordingly.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://host.docker.internal:11434 # or http://<ip>:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
# On Linux, add extra_hosts since host.docker.internal is not
|
||||||
|
# available automatically:
|
||||||
|
# extra_hosts:
|
||||||
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
llmproxy-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – External Ollama, PostgreSQL
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://host.docker.internal:11434 # or http://<ip>:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
# extra_hosts:
|
||||||
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: llmproxy
|
||||||
|
POSTGRES_USER: llmproxy
|
||||||
|
POSTGRES_PASSWORD: secret
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U llmproxy"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – Ollama as Container, SQLite
|
||||||
|
|
||||||
|
Ollama and llmproxy run together in Docker, data persisted in a volume.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://ollama:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
depends_on:
|
||||||
|
- ollama
|
||||||
|
|
||||||
|
ollama:
|
||||||
|
image: ollama/ollama:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- ollama-data:/root/.ollama
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
llmproxy-data:
|
||||||
|
ollama-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – Ollama as Container, PostgreSQL
|
||||||
|
|
||||||
|
For production environments with an external database.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://ollama:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
ollama:
|
||||||
|
condition: service_started
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: llmproxy
|
||||||
|
POSTGRES_USER: llmproxy
|
||||||
|
POSTGRES_PASSWORD: secret
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U llmproxy"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
ollama:
|
||||||
|
image: ollama/ollama:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- ollama-data:/root/.ollama
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg-data:
|
||||||
|
ollama-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-p 8000:8000 \
|
||||||
|
-e ADMIN_PASSWORD=changeme \
|
||||||
|
-e OLLAMA_URL=http://host.docker.internal:11434 \
|
||||||
|
-v llmproxy-data:/app/backend \
|
||||||
|
mediaeng/llmproxy:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Client Configuration
|
||||||
|
|
||||||
|
Configure the proxy as an OpenAI-compatible endpoint:
|
||||||
|
|
||||||
|
```
|
||||||
|
Base URL: http://<host>:8000/v1
|
||||||
|
API Key: <API key created in the admin interface>
|
||||||
|
```
|
||||||
+217
@@ -0,0 +1,217 @@
|
|||||||
|
# mediaeng/llmproxy
|
||||||
|
|
||||||
|
Ein schlanker Reverse-Proxy für [Ollama](https://ollama.com), der API-Keys mit konfigurierbaren Token- und Request-Quoten verwaltet. Eingehende Anfragen im OpenAI-kompatiblen Format werden authentifiziert, auf Quota geprüft und an den konfigurierten Ollama-Server weitergeleitet.
|
||||||
|
|
||||||
|
Ollama muss dabei nicht auf demselben Host laufen — `OLLAMA_URL` kann auf jeden erreichbaren Server zeigen, also auf den Docker-Host selbst, einen anderen Rechner im Netzwerk oder einen Remote-Server.
|
||||||
|
|
||||||
|
## Funktionen
|
||||||
|
|
||||||
|
- OpenAI-kompatibler Endpunkt (`/v1/chat/completions`, `/v1/models`)
|
||||||
|
- API-Key-Verwaltung mit tages- und monatlichen Token-/Request-Limits
|
||||||
|
- Web-basierte Admin-Oberfläche (Port 8001)
|
||||||
|
- Streaming-Support (Server-Sent Events)
|
||||||
|
- Tool-Use / Function Calling wird durchgereicht
|
||||||
|
- Rotierende Nutzungs-Logs
|
||||||
|
- SQLite (Standard) oder PostgreSQL
|
||||||
|
|
||||||
|
## Ports
|
||||||
|
|
||||||
|
| Port | Dienst |
|
||||||
|
|------|--------|
|
||||||
|
| `8000` | Proxy-Endpunkt (OpenAI-API) |
|
||||||
|
| `8001` | Admin-API + Web-Oberfläche |
|
||||||
|
|
||||||
|
Port 8001 muss exposed werden, da der Container die Admin-Oberfläche selbst auf diesem Port ausliefert. Um den Zugriff auf den lokalen Rechner zu beschränken, die Portbindung auf `127.0.0.1` setzen — so ist der Port nur vom Host erreichbar, nicht aus dem Netzwerk:
|
||||||
|
|
||||||
|
```
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Umgebungsvariablen
|
||||||
|
|
||||||
|
| Variable | Standard | Beschreibung |
|
||||||
|
|----------|----------|--------------|
|
||||||
|
| `ADMIN_PASSWORD` | – | **Pflicht.** Passwort für die Admin-Oberfläche |
|
||||||
|
| `OLLAMA_URL` | `http://localhost:11434` | URL des Ollama-Servers (ohne `/v1`-Suffix) |
|
||||||
|
| `DEFAULT_MODEL` | `llama3` | Modell, das verwendet wird wenn der Client keines angibt |
|
||||||
|
| `DATABASE_URL` | `sqlite:///./test.db` | Datenbank-Verbindungsstring (SQLite oder PostgreSQL) |
|
||||||
|
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxy |
|
||||||
|
| `PROXY_PORT` | `8000` | Port des Proxy |
|
||||||
|
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
||||||
|
| `APP_TZ` | `Europe/Berlin` | Zeitzone für Tages-/Monats-Reset der Quoten |
|
||||||
|
| `LOG_FILE` | `logs/usage.log` | Pfad der rotierenden Nutzungs-Logdatei |
|
||||||
|
|
||||||
|
## Docker Compose – Ollama extern, SQLite
|
||||||
|
|
||||||
|
Wenn Ollama außerhalb von Docker läuft — auf dem Docker-Host oder einem anderen erreichbaren Server. `OLLAMA_URL` entsprechend anpassen.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://host.docker.internal:11434 # oder http://<ip>:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
# Auf Linux extra_hosts ergänzen, da host.docker.internal dort
|
||||||
|
# nicht automatisch verfügbar ist:
|
||||||
|
# extra_hosts:
|
||||||
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
llmproxy-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – Ollama extern, PostgreSQL
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://host.docker.internal:11434 # oder http://<ip>:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
# extra_hosts:
|
||||||
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: llmproxy
|
||||||
|
POSTGRES_USER: llmproxy
|
||||||
|
POSTGRES_PASSWORD: secret
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U llmproxy"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – Ollama als Container, SQLite
|
||||||
|
|
||||||
|
Ollama und llmproxy laufen gemeinsam in Docker, Daten in einem Volume.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://ollama:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
depends_on:
|
||||||
|
- ollama
|
||||||
|
|
||||||
|
ollama:
|
||||||
|
image: ollama/ollama:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- ollama-data:/root/.ollama
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
llmproxy-data:
|
||||||
|
ollama-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – Ollama als Container, PostgreSQL
|
||||||
|
|
||||||
|
Für Produktionsumgebungen mit externer Datenbank.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://ollama:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
ollama:
|
||||||
|
condition: service_started
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: llmproxy
|
||||||
|
POSTGRES_USER: llmproxy
|
||||||
|
POSTGRES_PASSWORD: secret
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U llmproxy"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
ollama:
|
||||||
|
image: ollama/ollama:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- ollama-data:/root/.ollama
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg-data:
|
||||||
|
ollama-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Schnellstart
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-p 8000:8000 \
|
||||||
|
-e ADMIN_PASSWORD=changeme \
|
||||||
|
-e OLLAMA_URL=http://host.docker.internal:11434 \
|
||||||
|
-v llmproxy-data:/app/backend \
|
||||||
|
mediaeng/llmproxy:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Client-Konfiguration
|
||||||
|
|
||||||
|
Den Proxy als OpenAI-kompatibler Endpunkt konfigurieren:
|
||||||
|
|
||||||
|
```
|
||||||
|
Base URL: http://<host>:8000/v1
|
||||||
|
API Key: <angelegter API-Key aus der Admin-Oberfläche>
|
||||||
|
```
|
||||||
+1
-1
@@ -9,7 +9,7 @@ FROM python:3.12-slim
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY backend/requirements.txt .
|
COPY backend/requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt psycopg2-binary
|
||||||
|
|
||||||
COPY backend/ backend/
|
COPY backend/ backend/
|
||||||
COPY --from=frontend-builder /app/frontend/dist frontend/dist
|
COPY --from=frontend-builder /app/frontend/dist frontend/dist
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ async def read_api_keys(
|
|||||||
item.tokens_used_month = usage.tokens_used_month or 0
|
item.tokens_used_month = usage.tokens_used_month or 0
|
||||||
item.requests_today = usage.requests_today or 0
|
item.requests_today = usage.requests_today or 0
|
||||||
item.requests_month = usage.requests_month or 0
|
item.requests_month = usage.requests_month or 0
|
||||||
|
item.daily_reset_at = usage.daily_reset_at
|
||||||
|
item.monthly_reset_at = usage.monthly_reset_at
|
||||||
result.append(item)
|
result.append(item)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ class APIKeyWithUsage(APIKey):
|
|||||||
tokens_used_month: int = 0
|
tokens_used_month: int = 0
|
||||||
requests_today: int = 0
|
requests_today: int = 0
|
||||||
requests_month: int = 0
|
requests_month: int = 0
|
||||||
|
daily_reset_at: Optional[datetime] = None
|
||||||
|
monthly_reset_at: Optional[datetime] = None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
from_attributes = True
|
from_attributes = True
|
||||||
Executable
+40
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
IMAGE=mediaeng/llmproxy
|
||||||
|
PLATFORM=linux/arm64
|
||||||
|
|
||||||
|
CURRENT=$(git describe --tags --always)
|
||||||
|
if [ -z "$CURRENT" ]; then
|
||||||
|
echo "Fehler: git describe liefert kein Ergebnis"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Aktueller Tag: $CURRENT"
|
||||||
|
read -rp "Neuer Tag [${CURRENT}]: " INPUT
|
||||||
|
VERSION="${INPUT:-$CURRENT}"
|
||||||
|
|
||||||
|
if [ "$VERSION" != "$CURRENT" ]; then
|
||||||
|
git tag "$VERSION"
|
||||||
|
git push origin "$VERSION"
|
||||||
|
echo "Tag '$VERSION' gesetzt und gepusht."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Image : $IMAGE"
|
||||||
|
echo "Platform: $PLATFORM"
|
||||||
|
echo "Tags : $IMAGE:$VERSION $IMAGE:latest"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
docker buildx build \
|
||||||
|
--platform "$PLATFORM" \
|
||||||
|
--push \
|
||||||
|
-t "$IMAGE:$VERSION" \
|
||||||
|
-t "$IMAGE:latest" \
|
||||||
|
.
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Fertig. Gepusht:"
|
||||||
|
echo " docker pull $IMAGE:$VERSION"
|
||||||
|
echo " docker pull $IMAGE:latest"
|
||||||
+11
-24
@@ -1,24 +1,11 @@
|
|||||||
backend:
|
services:
|
||||||
build:
|
llmproxy:
|
||||||
context: ./backend
|
image: mediaeng/llmproxy:latest
|
||||||
dockerfile: Dockerfile
|
restart: unless-stopped
|
||||||
ports:
|
env_file: .env
|
||||||
- "8000:8000"
|
ports:
|
||||||
environment:
|
- "${PROXY_PORT:-8000}:${PROXY_PORT:-8000}"
|
||||||
- DATABASE_URL=postgresql://ollama:password@db:5432/ollama_proxy
|
- "127.0.0.1:8001:8001"
|
||||||
- OLLAMA_URL=http://ollama:11434
|
volumes:
|
||||||
- SECRET_KEY=your-secret-key-change-me
|
- ./backend/test.db:/app/backend/test.db
|
||||||
depends_on:
|
- ./backend/logs:/app/backend/logs
|
||||||
- db
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: postgres:16
|
|
||||||
environment:
|
|
||||||
- POSTGRES_USER=ollama
|
|
||||||
- POSTGRES_PASSWORD=password
|
|
||||||
- POSTGRES_DB=ollama_proxy
|
|
||||||
volumes:
|
|
||||||
- postgres_data:/var/lib/postgresql/data
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
postgres_data:
|
|
||||||
+18
-7
@@ -11,17 +11,28 @@ function authHeaders(token) {
|
|||||||
|
|
||||||
const fmtK = (n) => { const k = n / 1000; return k % 1 === 0 ? `${k}k` : `${k.toFixed(1)}k`; };
|
const fmtK = (n) => { const k = n / 1000; return k % 1 === 0 ? `${k}k` : `${k.toFixed(1)}k`; };
|
||||||
|
|
||||||
function QuotaBar({ used, limit, isToken = false }) {
|
function QuotaBar({ used, limit, isToken = false, since = null }) {
|
||||||
if (limit == null) return <span className="quota-unlimited">∞</span>;
|
const fmt = isToken ? fmtK : (n) => n.toLocaleString('de-DE');
|
||||||
|
const sinceLabel = since
|
||||||
|
? new Date(since).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit' })
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (limit == null) return (
|
||||||
|
<div className="quota-cell">
|
||||||
|
<span className="quota-unlimited">∞</span>
|
||||||
|
{sinceLabel && <span className="quota-since">seit {sinceLabel}</span>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
const pct = Math.min(100, (used / limit) * 100);
|
const pct = Math.min(100, (used / limit) * 100);
|
||||||
const color = pct >= 90 ? '#e74c3c' : pct >= 70 ? '#e67e22' : '#27ae60';
|
const color = pct >= 90 ? '#e74c3c' : pct >= 70 ? '#e67e22' : '#27ae60';
|
||||||
const fmt = isToken ? fmtK : (n) => n.toLocaleString('de-DE');
|
|
||||||
return (
|
return (
|
||||||
<div className="quota-cell">
|
<div className="quota-cell">
|
||||||
<span className="quota-label">{fmt(used)} / {fmt(limit)}</span>
|
<span className="quota-label">{fmt(used)} / {fmt(limit)}</span>
|
||||||
<div className="progress-bar">
|
<div className="progress-bar">
|
||||||
<div className="progress-fill" style={{ width: `${pct}%`, backgroundColor: color }} />
|
<div className="progress-fill" style={{ width: `${pct}%`, backgroundColor: color }} />
|
||||||
</div>
|
</div>
|
||||||
|
{sinceLabel && <span className="quota-since">seit {sinceLabel}</span>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -400,10 +411,10 @@ function App() {
|
|||||||
<td>{key.name}</td>
|
<td>{key.name}</td>
|
||||||
<td>{displayKey(key.key_prefix)}</td>
|
<td>{displayKey(key.key_prefix)}</td>
|
||||||
<td>{key.expires_at ? new Date(key.expires_at).toLocaleDateString('de-DE', { timeZone: 'Europe/Berlin' }) : '∞'}</td>
|
<td>{key.expires_at ? new Date(key.expires_at).toLocaleDateString('de-DE', { timeZone: 'Europe/Berlin' }) : '∞'}</td>
|
||||||
<td><QuotaBar used={key.tokens_used_today} limit={key.daily_tokens} isToken /></td>
|
<td><QuotaBar used={key.tokens_used_today} limit={key.daily_tokens} isToken since={key.daily_reset_at} /></td>
|
||||||
<td><QuotaBar used={key.tokens_used_month} limit={key.monthly_tokens} isToken /></td>
|
<td><QuotaBar used={key.tokens_used_month} limit={key.monthly_tokens} isToken since={key.monthly_reset_at} /></td>
|
||||||
<td><QuotaBar used={key.requests_today} limit={key.daily_requests} /></td>
|
<td><QuotaBar used={key.requests_today} limit={key.daily_requests} since={key.daily_reset_at} /></td>
|
||||||
<td><QuotaBar used={key.requests_month} limit={key.monthly_requests} /></td>
|
<td><QuotaBar used={key.requests_month} limit={key.monthly_requests} since={key.monthly_reset_at} /></td>
|
||||||
<td className="action-cell">
|
<td className="action-cell">
|
||||||
<button className="btn-icon btn-icon-edit" data-tooltip="Bearbeiten" onClick={() => handleEdit(key)}>✏</button>
|
<button className="btn-icon btn-icon-edit" data-tooltip="Bearbeiten" onClick={() => handleEdit(key)}>✏</button>
|
||||||
{key.is_active ? (
|
{key.is_active ? (
|
||||||
|
|||||||
@@ -246,6 +246,13 @@ tr:hover {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.quota-since {
|
||||||
|
display: block;
|
||||||
|
font-size: 10px;
|
||||||
|
color: #aaa;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
.progress-bar {
|
.progress-bar {
|
||||||
height: 4px;
|
height: 4px;
|
||||||
background: #e2e8f0;
|
background: #e2e8f0;
|
||||||
|
|||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Dev runner: startet Proxy, Admin-API und Frontend gemeinsam."""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
import threading
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def load_env(path: Path):
|
||||||
|
if not path.exists():
|
||||||
|
return
|
||||||
|
for line in path.read_text(encoding='utf-8').splitlines():
|
||||||
|
line = line.strip()
|
||||||
|
if line and not line.startswith('#') and '=' in line:
|
||||||
|
key, _, val = line.partition('=')
|
||||||
|
os.environ.setdefault(key.strip(), val.strip().strip('"\''))
|
||||||
|
|
||||||
|
|
||||||
|
def pipe_output(proc: subprocess.Popen, label: str, color: str):
|
||||||
|
reset = '\033[0m'
|
||||||
|
prefix = f'\033[{color}m[{label}]{reset} '
|
||||||
|
for raw in iter(proc.stdout.readline, b''):
|
||||||
|
sys.stdout.write(prefix + raw.decode(errors='replace'))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
root = Path(__file__).parent
|
||||||
|
load_env(root / '.env')
|
||||||
|
|
||||||
|
if not os.environ.get('ADMIN_PASSWORD'):
|
||||||
|
print('Fehler: ADMIN_PASSWORD nicht gesetzt (siehe .env)')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
python = root / '.venv' / 'bin' / 'python'
|
||||||
|
backend = root / 'backend'
|
||||||
|
frontend = root / 'frontend'
|
||||||
|
|
||||||
|
proxy_host = os.environ.get('PROXY_HOST', '0.0.0.0')
|
||||||
|
proxy_port = os.environ.get('PROXY_PORT', '8000')
|
||||||
|
admin_port = os.environ.get('ADMIN_PORT', '8001')
|
||||||
|
|
||||||
|
print('Initialisiere Datenbank...')
|
||||||
|
subprocess.run([str(python), 'init_db.py'], cwd=backend, check=True)
|
||||||
|
|
||||||
|
print(f'Starte Proxy → http://{proxy_host}:{proxy_port}')
|
||||||
|
print(f'Starte Admin-API → http://127.0.0.1:{admin_port}')
|
||||||
|
print('Starte Frontend → http://localhost:5173')
|
||||||
|
|
||||||
|
env = {**os.environ, 'PYTHONUNBUFFERED': '1'}
|
||||||
|
|
||||||
|
procs = [
|
||||||
|
(subprocess.Popen(
|
||||||
|
[str(python), '-m', 'uvicorn', 'main:app', '--reload',
|
||||||
|
'--host', proxy_host, '--port', proxy_port],
|
||||||
|
cwd=backend, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
|
||||||
|
), 'Proxy ', '34'), # blau
|
||||||
|
(subprocess.Popen(
|
||||||
|
[str(python), '-m', 'uvicorn', 'admin:app', '--reload',
|
||||||
|
'--host', '127.0.0.1', '--port', admin_port],
|
||||||
|
cwd=backend, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
|
||||||
|
), 'Admin ', '33'), # gelb
|
||||||
|
(subprocess.Popen(
|
||||||
|
['npm', 'run', 'dev'],
|
||||||
|
cwd=frontend, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
|
), 'Frontend', '32'), # grün
|
||||||
|
]
|
||||||
|
|
||||||
|
for proc, label, color in procs:
|
||||||
|
threading.Thread(target=pipe_output, args=(proc, label, color), daemon=True).start()
|
||||||
|
|
||||||
|
def stop(*_):
|
||||||
|
for p, _, _ in procs:
|
||||||
|
p.terminate()
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, stop)
|
||||||
|
signal.signal(signal.SIGTERM, stop)
|
||||||
|
|
||||||
|
for p, _, _ in procs:
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Reference in new issue
Block a user