Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07f6fec4bf | ||
|
|
6761a73364 | ||
|
|
0d1ce96c99 | ||
|
|
b16b3af44d | ||
|
|
fdbe0a74e8 | ||
|
|
0154c89c6b | ||
|
|
e3dbed9f5e | ||
|
|
5b37718120 | ||
|
|
f823e7d314 | ||
|
|
34b108f4df | ||
|
|
cced65693c | ||
|
|
256bafe30d | ||
|
|
555d9899fe | ||
|
|
31504d1a5b | ||
|
|
2e7b13227d | ||
|
|
5469981eb5 | ||
|
|
a1e293b1d7 |
No files matched your search
@@ -42,6 +42,8 @@ docker-compose.yml
|
|||||||
|
|
||||||
# Docs
|
# Docs
|
||||||
*.md
|
*.md
|
||||||
|
*.tex
|
||||||
|
*.pdf
|
||||||
|
|
||||||
# Dev & build scripts
|
# Dev & build scripts
|
||||||
run_dev.py
|
run_dev.py
|
||||||
|
|||||||
@@ -27,3 +27,7 @@ frontend/dist/
|
|||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
config.json
|
config.json
|
||||||
|
|
||||||
|
# Generated documents
|
||||||
|
KURZANLEITUNG.tex
|
||||||
|
KURZANLEITUNG.pdf
|
||||||
+18
-84
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
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.
|
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
|
## Features
|
||||||
|
|
||||||
- OpenAI-compatible endpoint (`/v1/chat/completions`, `/v1/models`)
|
- OpenAI-compatible endpoint (`/v1/chat/completions`, `/v1/models`)
|
||||||
- API key management with daily and monthly token/request limits
|
- API key management with daily and monthly token/request limits
|
||||||
- Web-based admin interface (port 8001)
|
- Web-based admin interface (port 8001)
|
||||||
|
- Model lock: enforces a specific model for all requests (useful for courses and lab sessions)
|
||||||
- Streaming support (Server-Sent Events)
|
- Streaming support (Server-Sent Events)
|
||||||
- Tool use / function calling passthrough
|
- Tool use / function calling passthrough
|
||||||
- Rotating usage logs
|
- Rotating usage logs
|
||||||
@@ -21,16 +20,7 @@ Ollama does not need to run on the same host — `OLLAMA_URL` can point to any r
|
|||||||
| `8000` | Proxy endpoint (OpenAI API) |
|
| `8000` | Proxy endpoint (OpenAI API) |
|
||||||
| `8001` | Admin API + web interface |
|
| `8001` | Admin API + web interface |
|
||||||
|
|
||||||
Port 8001 must be exposed because the container serves the admin interface directly on this port. All API endpoints require the `ADMIN_PASSWORD` — without a valid token, only the public frontend files (HTML/JS/CSS of the login page) are accessible. The password is therefore the primary protection.
|
All API endpoints require the `ADMIN_PASSWORD` — without a valid token, only the public frontend files (HTML/JS/CSS of the login page) are accessible. The password is therefore the primary protection.
|
||||||
|
|
||||||
Additional hardening: binding to `127.0.0.1` restricts access to the local host and prevents direct network access:
|
|
||||||
|
|
||||||
```
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:8001:8001" # local access only
|
|
||||||
# or:
|
|
||||||
- "8001:8001" # network-wide, protected by ADMIN_PASSWORD only
|
|
||||||
```
|
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
@@ -38,88 +28,43 @@ ports:
|
|||||||
|----------|---------|-------------|
|
|----------|---------|-------------|
|
||||||
| `ADMIN_PASSWORD` | – | **Required.** Password for the admin interface |
|
| `ADMIN_PASSWORD` | – | **Required.** Password for the admin interface |
|
||||||
| `OLLAMA_URL` | `http://localhost:11434` | URL of the Ollama server (without `/v1` suffix) |
|
| `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) |
|
| `DATABASE_URL` | `sqlite:///./test.db` | Database connection string (SQLite or PostgreSQL) |
|
||||||
| `PROXY_HOST` | `0.0.0.0` | Proxy bind address |
|
| `PROXY_HOST` | `0.0.0.0` | Proxy bind address |
|
||||||
| `PROXY_PORT` | `8000` | Proxy port |
|
| `PROXY_PORT` | `8000` | Proxy port |
|
||||||
|
| `ADMIN_HOST` | `0.0.0.0` | Admin API bind address (`127.0.0.1` to restrict to local access) |
|
||||||
| `ADMIN_PORT` | `8001` | Admin API port |
|
| `ADMIN_PORT` | `8001` | Admin API port |
|
||||||
| `APP_TZ` | `Europe/Berlin` | Timezone for daily/monthly quota resets |
|
| `APP_TZ` | `Europe/Berlin` | Timezone for daily/monthly quota resets |
|
||||||
| `LOG_FILE` | `logs/usage.log` | Path of the rotating usage log file |
|
| `LOG_FILE` | `logs/usage.log` | Path of the rotating usage log file |
|
||||||
|
|
||||||
## Docker Compose – External Ollama, SQLite
|
## Docker Compose – Ollama on the Host (Linux, recommended)
|
||||||
|
|
||||||
Use this when Ollama runs outside of Docker — on the Docker host or any other reachable server. Adjust `OLLAMA_URL` accordingly.
|
`network_mode: host` gives the container direct access to the host network stack. Ollama runs on the host and is reachable at `localhost:11434` — not visible from outside. The proxy and admin interface are available directly on host ports 8000 and 8001.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
llmproxy:
|
llmproxy:
|
||||||
image: mediaeng/llmproxy:latest
|
image: mediaeng/llmproxy:latest
|
||||||
|
container_name: llmproxy
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
network_mode: host
|
||||||
- "8000:8000"
|
env_file: .env
|
||||||
- "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:
|
volumes:
|
||||||
- llmproxy-data:/app/backend
|
- 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:
|
volumes:
|
||||||
llmproxy-data:
|
llmproxy-data:
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker Compose – External Ollama, PostgreSQL
|
`.env`:
|
||||||
|
```env
|
||||||
```yaml
|
ADMIN_PASSWORD=changeme
|
||||||
services:
|
OLLAMA_URL=http://localhost:11434
|
||||||
llmproxy:
|
APP_TZ=Europe/Berlin
|
||||||
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
|
## Docker Compose – Ollama as Container, SQLite
|
||||||
|
|
||||||
Ollama and llmproxy run together in Docker, data persisted in a volume.
|
Ollama and llmproxy run together in Docker. Ollama is not exposed externally.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
@@ -128,11 +73,11 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
- "127.0.0.1:8001:8001"
|
- "8001:8001"
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: changeme
|
ADMIN_PASSWORD: changeme
|
||||||
OLLAMA_URL: http://ollama:11434
|
OLLAMA_URL: http://ollama:11434
|
||||||
DEFAULT_MODEL: llama3
|
|
||||||
APP_TZ: Europe/Berlin
|
APP_TZ: Europe/Berlin
|
||||||
volumes:
|
volumes:
|
||||||
- llmproxy-data:/app/backend
|
- llmproxy-data:/app/backend
|
||||||
@@ -161,11 +106,11 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
- "127.0.0.1:8001:8001"
|
- "8001:8001"
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: changeme
|
ADMIN_PASSWORD: changeme
|
||||||
OLLAMA_URL: http://ollama:11434
|
OLLAMA_URL: http://ollama:11434
|
||||||
DEFAULT_MODEL: llama3
|
|
||||||
APP_TZ: Europe/Berlin
|
APP_TZ: Europe/Berlin
|
||||||
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -200,17 +145,6 @@ volumes:
|
|||||||
ollama-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
|
## Client Configuration
|
||||||
|
|
||||||
Configure the proxy as an OpenAI-compatible endpoint:
|
Configure the proxy as an OpenAI-compatible endpoint:
|
||||||
|
|||||||
+18
-84
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
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.
|
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
|
## Funktionen
|
||||||
|
|
||||||
- OpenAI-kompatibler Endpunkt (`/v1/chat/completions`, `/v1/models`)
|
- OpenAI-kompatibler Endpunkt (`/v1/chat/completions`, `/v1/models`)
|
||||||
- API-Key-Verwaltung mit tages- und monatlichen Token-/Request-Limits
|
- API-Key-Verwaltung mit tages- und monatlichen Token-/Request-Limits
|
||||||
- Web-basierte Admin-Oberfläche (Port 8001)
|
- Web-basierte Admin-Oberfläche (Port 8001)
|
||||||
|
- Modell-Lock: erzwingt ein bestimmtes Modell für alle Requests (nützlich für Praktika/Kurse)
|
||||||
- Streaming-Support (Server-Sent Events)
|
- Streaming-Support (Server-Sent Events)
|
||||||
- Tool-Use / Function Calling wird durchgereicht
|
- Tool-Use / Function Calling wird durchgereicht
|
||||||
- Rotierende Nutzungs-Logs
|
- Rotierende Nutzungs-Logs
|
||||||
@@ -21,16 +20,7 @@ Ollama muss dabei nicht auf demselben Host laufen — `OLLAMA_URL` kann auf jede
|
|||||||
| `8000` | Proxy-Endpunkt (OpenAI-API) |
|
| `8000` | Proxy-Endpunkt (OpenAI-API) |
|
||||||
| `8001` | Admin-API + Web-Oberfläche |
|
| `8001` | Admin-API + Web-Oberfläche |
|
||||||
|
|
||||||
Port 8001 muss exposed werden, da der Container die Admin-Oberfläche selbst auf diesem Port ausliefert. Alle API-Endpunkte erfordern das `ADMIN_PASSWORD` — ein Zugriff ohne gültiges Token liefert nur die öffentlichen Frontend-Dateien (HTML/JS/CSS der Login-Seite). Das Passwort ist damit die primäre Schutzmaßnahme.
|
Alle API-Endpunkte erfordern das `ADMIN_PASSWORD` — ein Zugriff ohne gültiges Token liefert nur die öffentlichen Frontend-Dateien (HTML/JS/CSS der Login-Seite). Das Passwort ist damit die primäre Schutzmaßnahme.
|
||||||
|
|
||||||
Zusätzliche Härtung: Portbindung auf `127.0.0.1` beschränkt den Zugriff auf den lokalen Host und verhindert direkten Netzwerkzugriff:
|
|
||||||
|
|
||||||
```
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:8001:8001" # nur lokal erreichbar
|
|
||||||
# oder:
|
|
||||||
- "8001:8001" # netzwerkweit, Schutz nur durch ADMIN_PASSWORD
|
|
||||||
```
|
|
||||||
|
|
||||||
## Umgebungsvariablen
|
## Umgebungsvariablen
|
||||||
|
|
||||||
@@ -38,88 +28,43 @@ ports:
|
|||||||
|----------|----------|--------------|
|
|----------|----------|--------------|
|
||||||
| `ADMIN_PASSWORD` | – | **Pflicht.** Passwort für die Admin-Oberfläche |
|
| `ADMIN_PASSWORD` | – | **Pflicht.** Passwort für die Admin-Oberfläche |
|
||||||
| `OLLAMA_URL` | `http://localhost:11434` | URL des Ollama-Servers (ohne `/v1`-Suffix) |
|
| `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) |
|
| `DATABASE_URL` | `sqlite:///./test.db` | Datenbank-Verbindungsstring (SQLite oder PostgreSQL) |
|
||||||
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxy |
|
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxy |
|
||||||
| `PROXY_PORT` | `8000` | Port des Proxy |
|
| `PROXY_PORT` | `8000` | Port des Proxy |
|
||||||
|
| `ADMIN_HOST` | `0.0.0.0` | Bind-Adresse der Admin-API (`127.0.0.1` für lokalen Zugriff) |
|
||||||
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
||||||
| `APP_TZ` | `Europe/Berlin` | Zeitzone für Tages-/Monats-Reset der Quoten |
|
| `APP_TZ` | `Europe/Berlin` | Zeitzone für Tages-/Monats-Reset der Quoten |
|
||||||
| `LOG_FILE` | `logs/usage.log` | Pfad der rotierenden Nutzungs-Logdatei |
|
| `LOG_FILE` | `logs/usage.log` | Pfad der rotierenden Nutzungs-Logdatei |
|
||||||
|
|
||||||
## Docker Compose – Ollama extern, SQLite
|
## Docker Compose – Ollama auf dem Host (Linux, empfohlen)
|
||||||
|
|
||||||
Wenn Ollama außerhalb von Docker läuft — auf dem Docker-Host oder einem anderen erreichbaren Server. `OLLAMA_URL` entsprechend anpassen.
|
`network_mode: host` gibt dem Container direkten Zugriff auf das Host-Netzwerk. Ollama läuft auf dem Host und ist über `localhost:11434` erreichbar — nach außen nicht sichtbar. Proxy und Admin-Oberfläche sind direkt auf den Host-Ports 8000 und 8001 verfügbar.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
llmproxy:
|
llmproxy:
|
||||||
image: mediaeng/llmproxy:latest
|
image: mediaeng/llmproxy:latest
|
||||||
|
container_name: llmproxy
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
network_mode: host
|
||||||
- "8000:8000"
|
env_file: .env
|
||||||
- "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:
|
volumes:
|
||||||
- llmproxy-data:/app/backend
|
- 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:
|
volumes:
|
||||||
llmproxy-data:
|
llmproxy-data:
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker Compose – Ollama extern, PostgreSQL
|
`.env`:
|
||||||
|
```env
|
||||||
```yaml
|
ADMIN_PASSWORD=changeme
|
||||||
services:
|
OLLAMA_URL=http://localhost:11434
|
||||||
llmproxy:
|
APP_TZ=Europe/Berlin
|
||||||
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
|
## Docker Compose – Ollama als Container, SQLite
|
||||||
|
|
||||||
Ollama und llmproxy laufen gemeinsam in Docker, Daten in einem Volume.
|
Ollama und llmproxy laufen gemeinsam in Docker. Ollama ist nicht nach außen exposed.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
@@ -128,11 +73,11 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
- "127.0.0.1:8001:8001"
|
- "8001:8001"
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: changeme
|
ADMIN_PASSWORD: changeme
|
||||||
OLLAMA_URL: http://ollama:11434
|
OLLAMA_URL: http://ollama:11434
|
||||||
DEFAULT_MODEL: llama3
|
|
||||||
APP_TZ: Europe/Berlin
|
APP_TZ: Europe/Berlin
|
||||||
volumes:
|
volumes:
|
||||||
- llmproxy-data:/app/backend
|
- llmproxy-data:/app/backend
|
||||||
@@ -161,11 +106,11 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
- "127.0.0.1:8001:8001"
|
- "8001:8001"
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: changeme
|
ADMIN_PASSWORD: changeme
|
||||||
OLLAMA_URL: http://ollama:11434
|
OLLAMA_URL: http://ollama:11434
|
||||||
DEFAULT_MODEL: llama3
|
|
||||||
APP_TZ: Europe/Berlin
|
APP_TZ: Europe/Berlin
|
||||||
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -200,17 +145,6 @@ volumes:
|
|||||||
ollama-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
|
## Client-Konfiguration
|
||||||
|
|
||||||
Den Proxy als OpenAI-kompatibler Endpunkt konfigurieren:
|
Den Proxy als OpenAI-kompatibler Endpunkt konfigurieren:
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ COPY frontend/ frontend/
|
|||||||
RUN npm run build --prefix frontend
|
RUN npm run build --prefix frontend
|
||||||
|
|
||||||
FROM python:3.12-slim
|
FROM python:3.12-slim
|
||||||
|
ARG APP_VERSION=dev
|
||||||
|
ENV APP_VERSION=$APP_VERSION
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY backend/requirements.txt .
|
COPY backend/requirements.txt .
|
||||||
|
|||||||
@@ -0,0 +1,183 @@
|
|||||||
|
# LLM-Dienst – Kurzanleitung
|
||||||
|
|
||||||
|
## Worum geht es?
|
||||||
|
|
||||||
|
Der Dienst stellt **große Sprachmodelle (LLMs)** über eine einfache HTTP-API bereit, die direkt aus Python-Skripten, Jupyter-Notebooks oder eigenen Anwendungen angesprochen werden kann. Die Modelle laufen lokal auf einem GPU-Server im Intranet – ohne Datenübertragung nach außen und ohne Cloud-Kosten.
|
||||||
|
|
||||||
|
Typische Anwendungsfälle:
|
||||||
|
|
||||||
|
- Texte zusammenfassen, übersetzen oder umformulieren
|
||||||
|
- KI-gestütztes Coding (z.B. mit **[opencode](https://opencode.ai)**)
|
||||||
|
- Experimente mit Prompt-Engineering und LLM-Integration in eigene Projekte
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Zugang
|
||||||
|
|
||||||
|
Der Dienst ist **nur im Intranet (VPN)** erreichbar.
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| **API-Endpunkt** | `http://141.75.33.244:8000` |
|
||||||
|
| **Authentifizierung** | API-Key erforderlich (per E-Mail beim Admin anfragen) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Verfügbare Modelle
|
||||||
|
|
||||||
|
| Modell | Größe | Hinweis |
|
||||||
|
|---|---|---|
|
||||||
|
| `gemma4:31b` | 19 GB | kompakt, schnell |
|
||||||
|
| `gpt-oss:20b` | 13 GB | kompakt, schnell |
|
||||||
|
| `gpt-oss:120b` | 65 GB | sehr leistungsfähig |
|
||||||
|
| `qwen3.5:122b` | 81 GB | sehr leistungsfähig |
|
||||||
|
| `qwen3-coder-next:q8_0` | 84 GB | speziell für Code |
|
||||||
|
|
||||||
|
> **Wichtig:** Es kann immer nur **ein Modell gleichzeitig** im GPU-Speicher geladen sein.
|
||||||
|
> Wechselt jemand das Modell, muss das vorherige entladen und das neue geladen werden –
|
||||||
|
> das kann **mehrere Minuten** dauern. Der erste Prompt nach einem Modellwechsel ist
|
||||||
|
> deshalb deutlich langsamer. Danach bleibt das Modell einige Zeit geladen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Python-Beispiel – Einfacher Prompt
|
||||||
|
|
||||||
|
Das API folgt dem **OpenAI-Standard**, d.h. die `openai`-Bibliothek kann direkt verwendet werden.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install openai
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openai import OpenAI
|
||||||
|
|
||||||
|
API_KEY = "sk-..." # euren API-Key eintragen
|
||||||
|
BASE_URL = "http://141.75.33.244:8000/v1"
|
||||||
|
MODEL = "gemma4:31b" # Modell nach Bedarf wählen
|
||||||
|
|
||||||
|
client = OpenAI(api_key=API_KEY, base_url=BASE_URL)
|
||||||
|
|
||||||
|
response = client.chat.completions.create(
|
||||||
|
model=MODEL,
|
||||||
|
messages=[
|
||||||
|
{"role": "user", "content": "Erkläre den Unterschied zwischen L1- und L2-Regularisierung."}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
print(response.choices[0].message.content)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Python-Beispiel – Verfügbare Modelle abfragen
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openai import OpenAI
|
||||||
|
|
||||||
|
API_KEY = "sk-..."
|
||||||
|
BASE_URL = "http://141.75.33.244:8000/v1"
|
||||||
|
|
||||||
|
client = OpenAI(api_key=API_KEY, base_url=BASE_URL)
|
||||||
|
|
||||||
|
models = client.models.list()
|
||||||
|
for m in models.data:
|
||||||
|
print(m.id)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Aktuell geladenes Modell abfragen
|
||||||
|
|
||||||
|
Da immer nur ein Modell gleichzeitig im Speicher sein kann, lässt sich mit folgendem Aufruf prüfen, welches Modell gerade aktiv ist:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
r = httpx.get(
|
||||||
|
"http://141.75.33.244:8000/api/ps",
|
||||||
|
headers={"Authorization": "Bearer sk-..."}
|
||||||
|
)
|
||||||
|
print(r.json())
|
||||||
|
```
|
||||||
|
|
||||||
|
Die Antwort enthält Modellname, Größe und wie lange das Modell noch im Speicher bleibt.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Empfehlungen zur Nutzung
|
||||||
|
|
||||||
|
- **Kleines Modell zuerst** (`gemma4:31b` oder `gpt-oss:20b`) – viel schneller, für viele Aufgaben ausreichend.
|
||||||
|
- **Großes Modell** nur bei komplexen Aufgaben (`qwen3.5:122b`, `gpt-oss:120b`).
|
||||||
|
- **Code-Aufgaben**: `qwen3-coder-next:q8_0` ist speziell dafür optimiert.
|
||||||
|
- Wenn möglich, **dasselbe Modell wie andere Nutzer** verwenden, um häufige Modellwechsel zu vermeiden.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Quotas
|
||||||
|
|
||||||
|
Je nach API-Key können folgende Limits konfiguriert sein:
|
||||||
|
|
||||||
|
- Maximale **Anfragen pro Tag / Monat**
|
||||||
|
- Maximale **Tokens pro Tag / Monat**
|
||||||
|
|
||||||
|
Bei Überschreitung gibt die API den Statuscode `429 Too Many Requests` zurück.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Coding-Assistent: opencode
|
||||||
|
|
||||||
|
[opencode](https://opencode.ai) ist ein terminal-basierter KI-Coding-Agent (ähnlich Claude Code), der OpenAI-kompatible APIs unterstützt und damit direkt auf den Intranet-Dienst zeigen kann.
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install -g opencode-ai
|
||||||
|
# oder
|
||||||
|
curl -fsSL https://opencode.ai/install | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
### Konfiguration
|
||||||
|
|
||||||
|
Konfigurationsdatei anlegen unter `~/.config/opencode/config.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"$schema": "https://opencode.ai/config.json",
|
||||||
|
"providers": {
|
||||||
|
"openai": {
|
||||||
|
"apiKey": "sk-...",
|
||||||
|
"baseURL": "http://141.75.33.244:8000/v1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model": "openai/qwen3-coder-next:q8_0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Für Code-Aufgaben empfiehlt sich `qwen3-coder-next:q8_0`, für allgemeine Aufgaben `gemma4:31b` oder `gpt-oss:20b`.
|
||||||
|
|
||||||
|
### Starten
|
||||||
|
|
||||||
|
```bash
|
||||||
|
opencode
|
||||||
|
```
|
||||||
|
|
||||||
|
opencode öffnet eine interaktive Terminal-Oberfläche und kann dann im Projektverzeichnis eingesetzt werden – Dateien lesen, Code generieren, Refactoring vorschlagen usw.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Administration (nur für Admins)
|
||||||
|
|
||||||
|
Das Web-Interface zur Verwaltung von API-Keys und Quotas ist erreichbar unter:
|
||||||
|
|
||||||
|
**`http://141.75.33.244:8001`**
|
||||||
|
|
||||||
|
Dort können API-Keys angelegt, deaktiviert und mit Quotas versehen werden.
|
||||||
|
|
||||||
|
### Modell-Lock für Praktika
|
||||||
|
|
||||||
|
Unter **Einstellungen → Aktives Modell (Lock)** kann ein Modell fest vorgegeben werden. Ist ein Lock gesetzt, wird das `model`-Feld in jedem Request durch dieses Modell ersetzt – unabhängig davon, was der Client schickt. Das verhindert unkoordinierte Modellwechsel während einer Veranstaltung, die alle Teilnehmenden durch lange Ladezeiten ausbremsen würden.
|
||||||
|
|
||||||
|
Typischer Ablauf für ein Praktikum:
|
||||||
|
1. Vor der Veranstaltung: passendes Modell in Ollama laden
|
||||||
|
2. Lock in der Admin-Oberfläche aktivieren
|
||||||
|
3. Nach der Veranstaltung: Lock wieder deaktivieren (Feld leeren)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Ollama Proxy mit API-Keys und Quotas
|
# Ollama Proxy mit API-Keys und Quotas
|
||||||
|
|
||||||
Ein Reverse-Proxy für Ollama mit API-Key-Authentifizierung, Quota-Management und Web-Admin-Oberfläche.
|
Ollama bietet von sich aus keine Authentifizierung — wer die API erreicht, kann sie nutzen. Dieses Projekt löst das Problem: Ollama bleibt an `localhost` gebunden und ist von außen nicht erreichbar. Vorgeschaltet läuft ein Proxy (Port 8000), der jeden Request auf einen gültigen API-Key prüft und optional Token- sowie Request-Quoten pro Key durchsetzt. Eine Web-Admin-Oberfläche (Port 8001) erlaubt das Verwalten von Keys, Quoten und Ollama-Einstellungen.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ Ein Reverse-Proxy für Ollama mit API-Key-Authentifizierung, Quota-Management un
|
|||||||
- Admin-Oberfläche passwortgeschützt (`ADMIN_PASSWORD`) — alle API-Endpunkte erfordern den Token
|
- Admin-Oberfläche passwortgeschützt (`ADMIN_PASSWORD`) — alle API-Endpunkte erfordern den Token
|
||||||
- API-Keys als SHA-256-Hash in der DB — Plaintext nur einmalig bei Erstellung
|
- API-Keys als SHA-256-Hash in der DB — Plaintext nur einmalig bei Erstellung
|
||||||
- Quota-Check atomar mit `SELECT FOR UPDATE` (kein TOCTOU-Race)
|
- Quota-Check atomar mit `SELECT FOR UPDATE` (kein TOCTOU-Race)
|
||||||
- Port 8001 kann optional auf `127.0.0.1` gebunden werden (zusätzliche Härtung)
|
- Admin-Port 8001 über `ADMIN_HOST=127.0.0.1` auf lokalen Zugriff beschränkbar
|
||||||
|
|
||||||
## Konfiguration
|
## Konfiguration
|
||||||
|
|
||||||
@@ -29,10 +29,10 @@ Ein Reverse-Proxy für Ollama mit API-Key-Authentifizierung, Quota-Management un
|
|||||||
ADMIN_PASSWORD=change-me
|
ADMIN_PASSWORD=change-me
|
||||||
PROXY_HOST=0.0.0.0
|
PROXY_HOST=0.0.0.0
|
||||||
PROXY_PORT=8000
|
PROXY_PORT=8000
|
||||||
|
ADMIN_HOST=0.0.0.0
|
||||||
ADMIN_PORT=8001
|
ADMIN_PORT=8001
|
||||||
DATABASE_URL=sqlite:///./test.db
|
DATABASE_URL=sqlite:///./test.db
|
||||||
OLLAMA_URL=http://localhost:11434
|
OLLAMA_URL=http://localhost:11434
|
||||||
DEFAULT_MODEL=llama3
|
|
||||||
APP_TZ=Europe/Berlin
|
APP_TZ=Europe/Berlin
|
||||||
LOG_FILE=logs/usage.log
|
LOG_FILE=logs/usage.log
|
||||||
```
|
```
|
||||||
@@ -42,10 +42,10 @@ LOG_FILE=logs/usage.log
|
|||||||
| `ADMIN_PASSWORD` | — | Passwort für die Admin-Oberfläche (**Pflicht**) |
|
| `ADMIN_PASSWORD` | — | Passwort für die Admin-Oberfläche (**Pflicht**) |
|
||||||
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxys |
|
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxys |
|
||||||
| `PROXY_PORT` | `8000` | Port des Proxys |
|
| `PROXY_PORT` | `8000` | Port des Proxys |
|
||||||
|
| `ADMIN_HOST` | `0.0.0.0` | Bind-Adresse der Admin-API (z. B. `127.0.0.1` für lokalen Zugriff) |
|
||||||
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
||||||
| `DATABASE_URL` | `sqlite:///./test.db` | DB-Verbindungsstring (SQLite oder PostgreSQL) |
|
| `DATABASE_URL` | `sqlite:///./test.db` | DB-Verbindungsstring (SQLite oder PostgreSQL) |
|
||||||
| `OLLAMA_URL` | `http://localhost:11434` | Adresse der Ollama-Instanz (auch in der UI änderbar) |
|
| `OLLAMA_URL` | `http://localhost:11434` | Adresse der Ollama-Instanz (auch in der UI änderbar) |
|
||||||
| `DEFAULT_MODEL` | `llama3` | Standard-Modell für `/v1/chat/completions` (auch in der UI änderbar) |
|
|
||||||
| `APP_TZ` | `Europe/Berlin` | Zeitzone für tägliche/monatliche Quota-Resets |
|
| `APP_TZ` | `Europe/Berlin` | Zeitzone für tägliche/monatliche Quota-Resets |
|
||||||
| `LOG_FILE` | `logs/usage.log` | Pfad der rotierenden Nutzungs-Logdatei |
|
| `LOG_FILE` | `logs/usage.log` | Pfad der rotierenden Nutzungs-Logdatei |
|
||||||
| `ALLOWED_ORIGINS` | `http://localhost:5173` | CORS-Origins (nur für Entwicklung relevant) |
|
| `ALLOWED_ORIGINS` | `http://localhost:5173` | CORS-Origins (nur für Entwicklung relevant) |
|
||||||
@@ -86,7 +86,13 @@ Admin-Oberfläche: `http://localhost:5173`
|
|||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
Zieht das Image von DockerHub, lädt Variablen aus `.env` und verwendet die lokale SQLite-Datenbank. Weitere Compose-Varianten (PostgreSQL, Ollama als Container) siehe `DOCKERHUB.md`.
|
Zieht das Image von DockerHub und lädt Variablen aus `.env`.
|
||||||
|
|
||||||
|
Das Setup verwendet `network_mode: host`: Der Container teilt den Netzwerkstack des Hosts, statt ein eigenes virtuelles Netzwerk zu bekommen. Das ist hier aus zwei Gründen die richtige Wahl:
|
||||||
|
|
||||||
|
1. **Ollama soll nicht von außen erreichbar sein.** Ollama läuft auf dem Host und ist an `127.0.0.1:11434` gebunden — nur lokal erreichbar. Mit einem eigenen Container-Netzwerk (Bridge-Mode) wäre `localhost` aus Sicht des Containers der Container selbst, nicht der Host. Die übliche Alternative (`host.docker.internal` + `extra_hosts`) ist auf Linux unzuverlässig.
|
||||||
|
|
||||||
|
2. **Kein doppeltes Port-Mapping nötig.** Mit `network_mode: host` sind Port 8000 und 8001 direkt auf dem Host verfügbar, ohne `ports:`-Einträge in der Compose-Datei.
|
||||||
|
|
||||||
### Image selbst bauen und pushen
|
### Image selbst bauen und pushen
|
||||||
|
|
||||||
@@ -98,15 +104,68 @@ Das Script zeigt den aktuellen Git-Tag, bietet an einen neuen zu setzen, baut da
|
|||||||
|
|
||||||
### Port 8001 (Admin)
|
### Port 8001 (Admin)
|
||||||
|
|
||||||
Port 8001 muss exposed werden, da der Container die Admin-Oberfläche auf diesem Port ausliefert. Alle API-Endpunkte erfordern das `ADMIN_PASSWORD` — der Token ist der primäre Schutz. Optionale zusätzliche Härtung: Bindung auf `127.0.0.1`:
|
Alle Admin-Endpunkte erfordern das `ADMIN_PASSWORD` — der Token ist der primäre Schutz. Für zusätzliche Härtung lässt sich die Admin-API auf lokalen Zugriff beschränken:
|
||||||
|
|
||||||
```yaml
|
```env
|
||||||
ports:
|
ADMIN_HOST=127.0.0.1
|
||||||
- "127.0.0.1:8001:8001" # nur lokal
|
|
||||||
# oder:
|
|
||||||
- "8001:8001" # netzwerkweit, Schutz durch ADMIN_PASSWORD
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Bei `network_mode: host` (Produktions-Standard) ist das die einzig wirksame Methode — Docker-Port-Mapping greift dort nicht.
|
||||||
|
|
||||||
|
### HTTPS via Reverse-Proxy (ungetestet)
|
||||||
|
|
||||||
|
Wer Proxy und Admin-Oberfläche per HTTPS bereitstellen will, kann einen weiteren Reverse-Proxy (z. B. Nginx oder Caddy) vorschalten. Bei `network_mode: host` lauschen beide Dienste direkt auf dem Host, Nginx/Caddy proxyen auf `localhost`.
|
||||||
|
|
||||||
|
**Caddy** (empfohlen — automatisches TLS via Let's Encrypt):
|
||||||
|
|
||||||
|
```
|
||||||
|
llm.example.com {
|
||||||
|
reverse_proxy localhost:8000 {
|
||||||
|
flush_interval -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
llm-admin.example.com {
|
||||||
|
reverse_proxy localhost:8001
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Nginx** (mit Certbot-Zertifikaten):
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
server_name llm.example.com;
|
||||||
|
|
||||||
|
ssl_certificate /etc/letsencrypt/live/llm.example.com/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/llm.example.com/privkey.pem;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_buffering off; # nötig für Streaming
|
||||||
|
proxy_cache off;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
server_name llm-admin.example.com;
|
||||||
|
|
||||||
|
ssl_certificate /etc/letsencrypt/live/llm-admin.example.com/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/llm-admin.example.com/privkey.pem;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8001;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Clients konfigurieren dann `https://llm.example.com/v1` als Base URL.
|
||||||
|
|
||||||
## Proxy-Endpunkte (Port 8000)
|
## Proxy-Endpunkte (Port 8000)
|
||||||
|
|
||||||
Alle Endpunkte erfordern einen gültigen API-Key im `Authorization`-Header.
|
Alle Endpunkte erfordern einen gültigen API-Key im `Authorization`-Header.
|
||||||
|
|||||||
+7
-4
@@ -131,13 +131,16 @@ async def get_proxy_info(_ = Depends(require_admin_auth)):
|
|||||||
host = os.getenv("PROXY_HOST", "0.0.0.0")
|
host = os.getenv("PROXY_HOST", "0.0.0.0")
|
||||||
port = os.getenv("PROXY_PORT", "8000")
|
port = os.getenv("PROXY_PORT", "8000")
|
||||||
display_host = "localhost" if host in ("0.0.0.0", "::") else host
|
display_host = "localhost" if host in ("0.0.0.0", "::") else host
|
||||||
return {"endpoint": f"http://{display_host}:{port}"}
|
return {
|
||||||
|
"endpoint": f"http://{display_host}:{port}",
|
||||||
|
"version": os.getenv("APP_VERSION", "dev"),
|
||||||
|
}
|
||||||
|
|
||||||
@app.get("/api/settings", response_model=schemas.Settings)
|
@app.get("/api/settings", response_model=schemas.Settings)
|
||||||
async def read_settings(db: Session = Depends(get_db), _ = Depends(require_admin_auth)):
|
async def read_settings(db: Session = Depends(get_db), _ = Depends(require_admin_auth)):
|
||||||
return schemas.Settings(
|
return schemas.Settings(
|
||||||
ollama_url=crud.get_setting(db, "ollama_url", "http://localhost:11434"),
|
ollama_url=crud.get_setting(db, "ollama_url", "http://localhost:11434"),
|
||||||
default_model=crud.get_setting(db, "default_model", "llama3"),
|
force_model=crud.get_setting(db, "force_model") or None,
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.put("/api/settings", response_model=schemas.Settings)
|
@app.put("/api/settings", response_model=schemas.Settings)
|
||||||
@@ -148,8 +151,8 @@ async def update_settings(
|
|||||||
):
|
):
|
||||||
ollama_url = settings.ollama_url.rstrip('/').removesuffix('/v1')
|
ollama_url = settings.ollama_url.rstrip('/').removesuffix('/v1')
|
||||||
crud.set_setting(db, "ollama_url", ollama_url)
|
crud.set_setting(db, "ollama_url", ollama_url)
|
||||||
crud.set_setting(db, "default_model", settings.default_model)
|
crud.set_setting(db, "force_model", settings.force_model or "")
|
||||||
return schemas.Settings(ollama_url=ollama_url, default_model=settings.default_model)
|
return schemas.Settings(ollama_url=ollama_url, force_model=settings.force_model or None)
|
||||||
|
|
||||||
@app.get("/api/ollama-models")
|
@app.get("/api/ollama-models")
|
||||||
async def get_ollama_models(
|
async def get_ollama_models(
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ def init_db():
|
|||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
if not get_setting(db, "ollama_url"):
|
if not get_setting(db, "ollama_url"):
|
||||||
set_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
set_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
||||||
if not get_setting(db, "default_model"):
|
|
||||||
set_setting(db, "default_model", os.getenv("DEFAULT_MODEL", "llama3"))
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
print("Database initialized.")
|
print("Database initialized.")
|
||||||
|
|||||||
+42
-9
@@ -70,8 +70,6 @@ def apply_env_settings():
|
|||||||
try:
|
try:
|
||||||
if url := os.getenv("OLLAMA_URL"):
|
if url := os.getenv("OLLAMA_URL"):
|
||||||
crud.set_setting(db, "ollama_url", url)
|
crud.set_setting(db, "ollama_url", url)
|
||||||
if model := os.getenv("DEFAULT_MODEL"):
|
|
||||||
crud.set_setting(db, "default_model", model)
|
|
||||||
db.commit()
|
db.commit()
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
@@ -91,6 +89,11 @@ async def proxy_request(url: str, method: str = "GET", json_data: dict = None):
|
|||||||
async def generate(request: Request, db: Session = Depends(get_db)):
|
async def generate(request: Request, db: Session = Depends(get_db)):
|
||||||
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
||||||
body = await request.json()
|
body = await request.json()
|
||||||
|
force_model = crud.get_setting(db, "force_model") or None
|
||||||
|
if force_model:
|
||||||
|
body = {**body, "model": force_model}
|
||||||
|
if not body.get("model"):
|
||||||
|
raise HTTPException(status_code=422, detail="Field 'model' is required")
|
||||||
prompt_tokens = crud.count_tokens(body.get("prompt", ""))
|
prompt_tokens = crud.count_tokens(body.get("prompt", ""))
|
||||||
|
|
||||||
if not crud.check_and_increment_quota(db, request.state.api_key_id, tokens=prompt_tokens, requests=1):
|
if not crud.check_and_increment_quota(db, request.state.api_key_id, tokens=prompt_tokens, requests=1):
|
||||||
@@ -101,7 +104,11 @@ async def generate(request: Request, db: Session = Depends(get_db)):
|
|||||||
request.state.api_key_name, body.get("model", "?"), prompt_tokens, prompt_preview)
|
request.state.api_key_name, body.get("model", "?"), prompt_tokens, prompt_preview)
|
||||||
try:
|
try:
|
||||||
response = await proxy_request(f"{ollama_url}/api/generate", method="POST", json_data=body)
|
response = await proxy_request(f"{ollama_url}/api/generate", method="POST", json_data=body)
|
||||||
return JSONResponse(content=response.json(), status_code=response.status_code)
|
resp_json = response.json()
|
||||||
|
usage_log.info('%s | /api/generate | %s | actual ↑%d ↓%d tokens',
|
||||||
|
request.state.api_key_name, body.get("model", "?"),
|
||||||
|
resp_json.get("prompt_eval_count", 0), resp_json.get("eval_count", 0))
|
||||||
|
return JSONResponse(content=resp_json, status_code=response.status_code)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
error_log.error("Proxy error | %s | /api/generate | %s | %s: %s",
|
error_log.error("Proxy error | %s | /api/generate | %s | %s: %s",
|
||||||
request.state.api_key_name, body.get("model", "?"), type(exc).__name__, exc, exc_info=exc)
|
request.state.api_key_name, body.get("model", "?"), type(exc).__name__, exc, exc_info=exc)
|
||||||
@@ -111,6 +118,11 @@ async def generate(request: Request, db: Session = Depends(get_db)):
|
|||||||
async def chat(request: Request, db: Session = Depends(get_db)):
|
async def chat(request: Request, db: Session = Depends(get_db)):
|
||||||
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
||||||
body = await request.json()
|
body = await request.json()
|
||||||
|
force_model = crud.get_setting(db, "force_model") or None
|
||||||
|
if force_model:
|
||||||
|
body = {**body, "model": force_model}
|
||||||
|
if not body.get("model"):
|
||||||
|
raise HTTPException(status_code=422, detail="Field 'model' is required")
|
||||||
messages = body.get("messages", [])
|
messages = body.get("messages", [])
|
||||||
prompt_tokens = sum(crud.count_tokens(_content_to_str(msg.get("content"))) for msg in messages)
|
prompt_tokens = sum(crud.count_tokens(_content_to_str(msg.get("content"))) for msg in messages)
|
||||||
|
|
||||||
@@ -121,7 +133,11 @@ async def chat(request: Request, db: Session = Depends(get_db)):
|
|||||||
request.state.api_key_name, body.get("model", "?"), prompt_tokens, _last_user_msg(messages))
|
request.state.api_key_name, body.get("model", "?"), prompt_tokens, _last_user_msg(messages))
|
||||||
try:
|
try:
|
||||||
response = await proxy_request(f"{ollama_url}/api/chat", method="POST", json_data=body)
|
response = await proxy_request(f"{ollama_url}/api/chat", method="POST", json_data=body)
|
||||||
return JSONResponse(content=response.json(), status_code=response.status_code)
|
resp_json = response.json()
|
||||||
|
usage_log.info('%s | /api/chat | %s | actual ↑%d ↓%d tokens',
|
||||||
|
request.state.api_key_name, body.get("model", "?"),
|
||||||
|
resp_json.get("prompt_eval_count", 0), resp_json.get("eval_count", 0))
|
||||||
|
return JSONResponse(content=resp_json, status_code=response.status_code)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
error_log.error("Proxy error | %s | /api/chat | %s | %s: %s",
|
error_log.error("Proxy error | %s | /api/chat | %s | %s: %s",
|
||||||
request.state.api_key_name, body.get("model", "?"), type(exc).__name__, exc, exc_info=exc)
|
request.state.api_key_name, body.get("model", "?"), type(exc).__name__, exc, exc_info=exc)
|
||||||
@@ -133,6 +149,16 @@ async def list_models(db: Session = Depends(get_db)):
|
|||||||
response = await proxy_request(f"{ollama_url}/api/tags", method="GET")
|
response = await proxy_request(f"{ollama_url}/api/tags", method="GET")
|
||||||
return JSONResponse(content=response.json(), status_code=response.status_code)
|
return JSONResponse(content=response.json(), status_code=response.status_code)
|
||||||
|
|
||||||
|
@app.get("/version")
|
||||||
|
async def version():
|
||||||
|
return {"version": os.getenv("APP_VERSION", "dev")}
|
||||||
|
|
||||||
|
@app.get("/api/ps")
|
||||||
|
async def running_models(db: Session = Depends(get_db)):
|
||||||
|
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
||||||
|
response = await proxy_request(f"{ollama_url}/api/ps", method="GET")
|
||||||
|
return JSONResponse(content=response.json(), status_code=response.status_code)
|
||||||
|
|
||||||
@app.get("/api/versions")
|
@app.get("/api/versions")
|
||||||
async def versions(db: Session = Depends(get_db)):
|
async def versions(db: Session = Depends(get_db)):
|
||||||
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
||||||
@@ -148,19 +174,21 @@ async def list_openai_models(db: Session = Depends(get_db)):
|
|||||||
@app.post("/v1/chat/completions")
|
@app.post("/v1/chat/completions")
|
||||||
async def openai_chat_completions(request: Request, db: Session = Depends(get_db)):
|
async def openai_chat_completions(request: Request, db: Session = Depends(get_db)):
|
||||||
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
ollama_url = crud.get_setting(db, "ollama_url", os.getenv("OLLAMA_URL", "http://localhost:11434"))
|
||||||
default_model = crud.get_setting(db, "default_model", os.getenv("DEFAULT_MODEL", "llama3"))
|
|
||||||
|
|
||||||
body = await request.json()
|
body = await request.json()
|
||||||
|
force_model = crud.get_setting(db, "force_model") or None
|
||||||
|
if force_model:
|
||||||
|
body = {**body, "model": force_model}
|
||||||
|
if not body.get("model"):
|
||||||
|
raise HTTPException(status_code=422, detail="Field 'model' is required")
|
||||||
messages = body.get("messages", [])
|
messages = body.get("messages", [])
|
||||||
prompt_tokens = sum(crud.count_tokens(_content_to_str(msg.get("content"))) for msg in messages)
|
prompt_tokens = sum(crud.count_tokens(_content_to_str(msg.get("content"))) for msg in messages)
|
||||||
|
|
||||||
if not crud.check_and_increment_quota(db, request.state.api_key_id, tokens=prompt_tokens, requests=1):
|
if not crud.check_and_increment_quota(db, request.state.api_key_id, tokens=prompt_tokens, requests=1):
|
||||||
raise HTTPException(status_code=429, detail="Quota exceeded")
|
raise HTTPException(status_code=429, detail="Quota exceeded")
|
||||||
|
|
||||||
if "model" not in body:
|
|
||||||
body = {**body, "model": default_model}
|
|
||||||
|
|
||||||
model_name = body["model"]
|
model_name = body["model"]
|
||||||
|
|
||||||
usage_log.info('%s | /v1/chat/completions | %s | ~%d tokens | "%s"',
|
usage_log.info('%s | /v1/chat/completions | %s | ~%d tokens | "%s"',
|
||||||
request.state.api_key_name, model_name, prompt_tokens, _last_user_msg(messages))
|
request.state.api_key_name, model_name, prompt_tokens, _last_user_msg(messages))
|
||||||
|
|
||||||
@@ -185,7 +213,12 @@ async def openai_chat_completions(request: Request, db: Session = Depends(get_db
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
response = await proxy_request(target, method="POST", json_data=body)
|
response = await proxy_request(target, method="POST", json_data=body)
|
||||||
return JSONResponse(content=response.json(), status_code=response.status_code)
|
resp_json = response.json()
|
||||||
|
usage = resp_json.get("usage", {})
|
||||||
|
usage_log.info('%s | /v1/chat/completions | %s | actual ↑%d ↓%d tokens',
|
||||||
|
request.state.api_key_name, model_name,
|
||||||
|
usage.get("prompt_tokens", 0), usage.get("completion_tokens", 0))
|
||||||
|
return JSONResponse(content=resp_json, status_code=response.status_code)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
error_log.error("Proxy error | %s | /v1/chat/completions | %s | %s: %s",
|
error_log.error("Proxy error | %s | /v1/chat/completions | %s | %s: %s",
|
||||||
request.state.api_key_name, model_name, type(exc).__name__, exc, exc_info=exc)
|
request.state.api_key_name, model_name, type(exc).__name__, exc, exc_info=exc)
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ class QuotaUpdate(BaseModel):
|
|||||||
|
|
||||||
class Settings(BaseModel):
|
class Settings(BaseModel):
|
||||||
ollama_url: str
|
ollama_url: str
|
||||||
default_model: str
|
force_model: Optional[str] = None
|
||||||
|
|
||||||
class UsageStats(BaseModel):
|
class UsageStats(BaseModel):
|
||||||
tokens_used_today: int = 0
|
tokens_used_today: int = 0
|
||||||
|
|||||||
+16
-8
@@ -5,17 +5,24 @@ cd "$(dirname "$0")"
|
|||||||
IMAGE=mediaeng/llmproxy
|
IMAGE=mediaeng/llmproxy
|
||||||
PLATFORM=linux/arm64
|
PLATFORM=linux/arm64
|
||||||
|
|
||||||
CURRENT=$(git describe --tags --always)
|
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
|
||||||
if [ -z "$CURRENT" ]; then
|
HEAD_TAG=$(git tag --points-at HEAD | head -1)
|
||||||
echo "Fehler: git describe liefert kein Ergebnis"
|
|
||||||
|
if [ -n "$HEAD_TAG" ]; then
|
||||||
|
echo "HEAD bereits getaggt: $HEAD_TAG"
|
||||||
|
read -rp "Neuer Tag [${HEAD_TAG}]: " INPUT
|
||||||
|
VERSION="${INPUT:-$HEAD_TAG}"
|
||||||
|
else
|
||||||
|
echo "Letzter Tag: ${LAST_TAG:-kein Tag}"
|
||||||
|
read -rp "Neuer Tag: " INPUT
|
||||||
|
if [ -z "$INPUT" ]; then
|
||||||
|
echo "Kein Tag angegeben, breche ab."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
VERSION="$INPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Aktueller Tag: $CURRENT"
|
if [ "$VERSION" != "$HEAD_TAG" ]; then
|
||||||
read -rp "Neuer Tag [${CURRENT}]: " INPUT
|
|
||||||
VERSION="${INPUT:-$CURRENT}"
|
|
||||||
|
|
||||||
if [ "$VERSION" != "$CURRENT" ]; then
|
|
||||||
git tag "$VERSION"
|
git tag "$VERSION"
|
||||||
git push origin "$VERSION"
|
git push origin "$VERSION"
|
||||||
echo "Tag '$VERSION' gesetzt und gepusht."
|
echo "Tag '$VERSION' gesetzt und gepusht."
|
||||||
@@ -30,6 +37,7 @@ echo ""
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform "$PLATFORM" \
|
--platform "$PLATFORM" \
|
||||||
--push \
|
--push \
|
||||||
|
--build-arg APP_VERSION="$VERSION" \
|
||||||
-t "$IMAGE:$VERSION" \
|
-t "$IMAGE:$VERSION" \
|
||||||
-t "$IMAGE:latest" \
|
-t "$IMAGE:latest" \
|
||||||
.
|
.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ uvicorn main:app \
|
|||||||
PROXY_PID=$!
|
PROXY_PID=$!
|
||||||
|
|
||||||
uvicorn admin:app \
|
uvicorn admin:app \
|
||||||
--host "0.0.0.0" \
|
--host "${ADMIN_HOST:-0.0.0.0}" \
|
||||||
--port "${ADMIN_PORT:-8001}" &
|
--port "${ADMIN_PORT:-8001}" &
|
||||||
ADMIN_PID=$!
|
ADMIN_PID=$!
|
||||||
|
|
||||||
|
|||||||
+17
-11
@@ -82,6 +82,7 @@ function SettingsSection({ password }) {
|
|||||||
const [modelsLoading, setModelsLoading] = useState(false);
|
const [modelsLoading, setModelsLoading] = useState(false);
|
||||||
const [ollamaReachable, setOllamaReachable] = useState(true);
|
const [ollamaReachable, setOllamaReachable] = useState(true);
|
||||||
const [proxyEndpoint, setProxyEndpoint] = useState(null);
|
const [proxyEndpoint, setProxyEndpoint] = useState(null);
|
||||||
|
const [appVersion, setAppVersion] = useState(null);
|
||||||
const [saved, setSaved] = useState(false);
|
const [saved, setSaved] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
@@ -95,8 +96,8 @@ function SettingsSection({ password }) {
|
|||||||
const { models, reachable } = res.data;
|
const { models, reachable } = res.data;
|
||||||
setOllamaReachable(reachable);
|
setOllamaReachable(reachable);
|
||||||
setAvailableModels(models);
|
setAvailableModels(models);
|
||||||
if (models.length > 0 && !models.includes(currentModel)) {
|
if (models.length > 0 && currentModel && !models.includes(currentModel)) {
|
||||||
setSettings(s => ({ ...s, default_model: models[0] }));
|
setSettings(s => ({ ...s, force_model: models[0] }));
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
setOllamaReachable(false);
|
setOllamaReachable(false);
|
||||||
@@ -115,7 +116,8 @@ function SettingsSection({ password }) {
|
|||||||
const s = settingsRes.data;
|
const s = settingsRes.data;
|
||||||
setSettings(s);
|
setSettings(s);
|
||||||
setProxyEndpoint(proxyRes.data.endpoint);
|
setProxyEndpoint(proxyRes.data.endpoint);
|
||||||
fetchModels(s.ollama_url, s.default_model);
|
setAppVersion(proxyRes.data.version);
|
||||||
|
fetchModels(s.ollama_url, s.force_model);
|
||||||
}).catch(() => setError('Einstellungen konnten nicht geladen werden.'));
|
}).catch(() => setError('Einstellungen konnten nicht geladen werden.'));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -145,6 +147,10 @@ function SettingsSection({ password }) {
|
|||||||
<small> (Änderung erfordert Neustart)</small>
|
<small> (Änderung erfordert Neustart)</small>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="settings-row">
|
||||||
|
<label>Version</label>
|
||||||
|
<span className="settings-value">{appVersion ?? '…'}</span>
|
||||||
|
</div>
|
||||||
<div className="settings-row">
|
<div className="settings-row">
|
||||||
<label>Ollama-Endpunkt</label>
|
<label>Ollama-Endpunkt</label>
|
||||||
<div className="settings-input-wrap">
|
<div className="settings-input-wrap">
|
||||||
@@ -152,7 +158,7 @@ function SettingsSection({ password }) {
|
|||||||
type="url"
|
type="url"
|
||||||
value={settings.ollama_url}
|
value={settings.ollama_url}
|
||||||
onChange={(e) => setSettings({ ...settings, ollama_url: e.target.value })}
|
onChange={(e) => setSettings({ ...settings, ollama_url: e.target.value })}
|
||||||
onBlur={(e) => fetchModels(e.target.value, settings.default_model)}
|
onBlur={(e) => fetchModels(e.target.value, settings.force_model)}
|
||||||
placeholder="http://localhost:11434"
|
placeholder="http://localhost:11434"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@@ -162,23 +168,23 @@ function SettingsSection({ password }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="settings-row">
|
<div className="settings-row">
|
||||||
<label>Standard-Modell</label>
|
<label>Aktives Modell (Lock)</label>
|
||||||
{modelsLoading ? (
|
{modelsLoading ? (
|
||||||
<span className="settings-value">Lade Modelle…</span>
|
<span className="settings-value">Lade Modelle…</span>
|
||||||
) : availableModels.length > 0 ? (
|
) : availableModels.length > 0 ? (
|
||||||
<select
|
<select
|
||||||
value={settings.default_model}
|
value={settings.force_model || ""}
|
||||||
onChange={(e) => setSettings({ ...settings, default_model: e.target.value })}
|
onChange={(e) => setSettings({ ...settings, force_model: e.target.value || null })}
|
||||||
>
|
>
|
||||||
|
<option value="">— kein Lock —</option>
|
||||||
{availableModels.map(m => <option key={m} value={m}>{m}</option>)}
|
{availableModels.map(m => <option key={m} value={m}>{m}</option>)}
|
||||||
</select>
|
</select>
|
||||||
) : (
|
) : (
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={settings.default_model}
|
value={settings.force_model || ""}
|
||||||
onChange={(e) => setSettings({ ...settings, default_model: e.target.value })}
|
onChange={(e) => setSettings({ ...settings, force_model: e.target.value || null })}
|
||||||
placeholder="llama3"
|
placeholder="leer = kein Lock"
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+3
-2
@@ -40,13 +40,14 @@ def main():
|
|||||||
|
|
||||||
proxy_host = os.environ.get('PROXY_HOST', '0.0.0.0')
|
proxy_host = os.environ.get('PROXY_HOST', '0.0.0.0')
|
||||||
proxy_port = os.environ.get('PROXY_PORT', '8000')
|
proxy_port = os.environ.get('PROXY_PORT', '8000')
|
||||||
|
admin_host = os.environ.get('ADMIN_HOST', '127.0.0.1')
|
||||||
admin_port = os.environ.get('ADMIN_PORT', '8001')
|
admin_port = os.environ.get('ADMIN_PORT', '8001')
|
||||||
|
|
||||||
print('Initialisiere Datenbank...')
|
print('Initialisiere Datenbank...')
|
||||||
subprocess.run([str(python), 'init_db.py'], cwd=backend, check=True)
|
subprocess.run([str(python), 'init_db.py'], cwd=backend, check=True)
|
||||||
|
|
||||||
print(f'Starte Proxy → http://{proxy_host}:{proxy_port}')
|
print(f'Starte Proxy → http://{proxy_host}:{proxy_port}')
|
||||||
print(f'Starte Admin-API → http://127.0.0.1:{admin_port}')
|
print(f'Starte Admin-API → http://{admin_host}:{admin_port}')
|
||||||
print('Starte Frontend → http://localhost:5173')
|
print('Starte Frontend → http://localhost:5173')
|
||||||
|
|
||||||
env = {**os.environ, 'PYTHONUNBUFFERED': '1'}
|
env = {**os.environ, 'PYTHONUNBUFFERED': '1'}
|
||||||
@@ -59,7 +60,7 @@ def main():
|
|||||||
), 'Proxy ', '34'), # blau
|
), 'Proxy ', '34'), # blau
|
||||||
(subprocess.Popen(
|
(subprocess.Popen(
|
||||||
[str(python), '-m', 'uvicorn', 'admin:app', '--reload',
|
[str(python), '-m', 'uvicorn', 'admin:app', '--reload',
|
||||||
'--host', '127.0.0.1', '--port', admin_port],
|
'--host', admin_host, '--port', admin_port],
|
||||||
cwd=backend, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
|
cwd=backend, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
|
||||||
), 'Admin ', '33'), # gelb
|
), 'Admin ', '33'), # gelb
|
||||||
(subprocess.Popen(
|
(subprocess.Popen(
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ fi
|
|||||||
|
|
||||||
PROXY_HOST=${PROXY_HOST:-0.0.0.0}
|
PROXY_HOST=${PROXY_HOST:-0.0.0.0}
|
||||||
PROXY_PORT=${PROXY_PORT:-8000}
|
PROXY_PORT=${PROXY_PORT:-8000}
|
||||||
|
ADMIN_HOST=${ADMIN_HOST:-127.0.0.1}
|
||||||
ADMIN_PORT=${ADMIN_PORT:-8001}
|
ADMIN_PORT=${ADMIN_PORT:-8001}
|
||||||
FRONTEND_PORT=5173
|
FRONTEND_PORT=5173
|
||||||
|
|
||||||
@@ -60,9 +61,8 @@ cd backend
|
|||||||
python3 -m uvicorn main:app --reload --host "$PROXY_HOST" --port "$PROXY_PORT" &
|
python3 -m uvicorn main:app --reload --host "$PROXY_HOST" --port "$PROXY_PORT" &
|
||||||
PIDS+=($!)
|
PIDS+=($!)
|
||||||
|
|
||||||
# Admin-API immer nur lokal erreichbar (Host nicht konfigurierbar)
|
echo "Starte Admin-API auf ${ADMIN_HOST}:${ADMIN_PORT}..."
|
||||||
echo "Starte Admin-API auf 127.0.0.1:${ADMIN_PORT}..."
|
python3 -m uvicorn admin:app --reload --host "$ADMIN_HOST" --port "$ADMIN_PORT" &
|
||||||
python3 -m uvicorn admin:app --reload --host 127.0.0.1 --port "$ADMIN_PORT" &
|
|
||||||
PIDS+=($!)
|
PIDS+=($!)
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ PIDS+=($!)
|
|||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
echo "Backend läuft (Port $PROXY_PORT)"
|
echo "Backend läuft (Port $PROXY_PORT)"
|
||||||
echo "Admin-API läuft (Port $ADMIN_PORT, nur lokal)"
|
echo "Admin-API läuft (${ADMIN_HOST}:${ADMIN_PORT})"
|
||||||
echo "Admin-Oberfläche: http://localhost:$FRONTEND_PORT"
|
echo "Admin-Oberfläche: http://localhost:$FRONTEND_PORT"
|
||||||
|
|
||||||
wait
|
wait
|
||||||
Reference in new issue
Block a user