#!/usr/bin/env bash # End to end demonstration of llm-gateway (bash / curl equivalent of demo.ps1). # # ./demo.sh --mock # ./demo.sh --port 8099 --provider chatgpt set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$ROOT" PORT=8099 PROVIDER=chatgpt MOCK=0 while [[ $# -gt 0 ]]; do case "$1" in --mock) MOCK=1; shift ;; --port) PORT="$2"; shift 2 ;; --provider) PROVIDER="$2"; shift 2 ;; *) echo "unknown option: $1" >&2; exit 1 ;; esac done BACKEND="browser" [[ "$MOCK" == "1" ]] && BACKEND="mock" BASE="http://127.0.0.1:$PORT" STATE="$ROOT/.demo-state" mkdir -p "$STATE" # shellcheck disable=SC2030 export LLM_GATEWAY_HOME="$STATE" echo "== building ==" cargo build --quiet EXE="$ROOT/target/debug/llm-gateway" echo "== starting llm-gateway (backend: $BACKEND, port: $PORT) ==" "$EXE" serve --port "$PORT" --backend "$BACKEND" & SERVER_PID=$! trap 'echo; echo "== stopping the server =="; kill "$SERVER_PID" 2>/dev/null || true' EXIT for _ in $(seq 1 60); do if curl -sf "$BASE/health" >/dev/null 2>&1; then break; fi sleep 0.5 done echo echo "== /health ==" curl -s "$BASE/health" | python3 -m json.tool 2>/dev/null || curl -s "$BASE/health" echo echo "== /v1/models ==" curl -s "$BASE/v1/models" echo echo "== POST /v1/chat/completions (non-streaming) ==" curl -s "$BASE/v1/chat/completions" \ -H 'content-type: application/json' \ -d "{\"model\":\"$PROVIDER\",\"messages\":[{\"role\":\"user\",\"content\":\"Say ok and nothing else.\"}]}" echo echo "== POST /v1/chat/completions (two completions) ==" curl -s "$BASE/v1/chat/completions" \ -H 'content-type: application/json' \ -d "{\"model\":\"$PROVIDER\",\"n\":2,\"messages\":[{\"role\":\"user\",\"content\":\"Answer with one word.\"}]}" echo echo "== accounts of $PROVIDER (when the provider file declares some) ==" curl -s "$BASE/health" | grep -o '"accounts":\[[^]]*\]' || echo " none declared" echo echo "== POST /v1/chat/completions (streaming, first lines) ==" curl -sN "$BASE/v1/chat/completions" \ -H 'content-type: application/json' \ -d "{\"model\":\"$PROVIDER\",\"stream\":true,\"messages\":[{\"role\":\"user\",\"content\":\"Count from one to five.\"}]}" | head -n 12 || true echo echo "== GET /v1/providers/$PROVIDER/status ==" curl -s "$BASE/v1/providers/$PROVIDER/status" echo echo "== POST /v1/providers/$PROVIDER/validate ==" curl -s -X POST "$BASE/v1/providers/$PROVIDER/validate" echo echo "== POST /v1/admin/reload ==" curl -s -X POST "$BASE/v1/admin/reload" echo echo "== dashboard ==" echo " $BASE/dashboard" echo " state directory: $STATE"