Initial commit: llm-router — smart OpenAI/Anthropic/Ollama router
A stdlib pre-router in front of Ollama with LiteLLM backend: - auto model selection by content/tools/modality, with fallbacks - OpenAI /v1, Anthropic /v1/messages, and Ollama-native /api/* endpoints - Whisper-shaped /v1/audio/transcriptions + in-chat audio - key-based fleet policies (e.g. force a client onto uncensored models) - optional Bearer auth; launchd/systemd service install - benchmark harnesses (speed, quality, agentic tool use) with sample results Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# Create a copy of an Ollama model with a fixed context window (num_ctx).
|
||||
# Useful because Ollama's default context is small and large prompts get truncated.
|
||||
#
|
||||
# Usage: ./scripts/make-context-variant.sh <base-model> <num_ctx> [new-tag]
|
||||
# Example: ./scripts/make-context-variant.sh glm-4.7-flash 131072 glm-4.7-flash:128k
|
||||
#
|
||||
# Memory note: KV cache grows with num_ctx. On a 36 GB unified-memory Mac, keep
|
||||
# the model + KV under ~27 GB (the default GPU wired ceiling) to avoid swapping.
|
||||
set -euo pipefail
|
||||
BASE="${1:?usage: make-context-variant.sh <base-model> <num_ctx> [new-tag]}"
|
||||
NCTX="${2:?need a num_ctx value, e.g. 65536}"
|
||||
TAG="${3:-${BASE%%:*}:${NCTX}ctx}"
|
||||
|
||||
TMP="$(mktemp -t Modelfile.XXXXXX)"
|
||||
printf 'FROM %s\nPARAMETER num_ctx %s\n' "$BASE" "$NCTX" > "$TMP"
|
||||
ollama create "$TAG" -f "$TMP"
|
||||
rm -f "$TMP"
|
||||
echo ">> created $TAG (num_ctx=$NCTX from $BASE)"
|
||||
ollama show "$TAG" | grep -i num_ctx || true
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# Pull a model fleet into Ollama. EDIT the MODELS list to taste, then run.
|
||||
# Continues past failures; prints a summary. Ollama resumes partial downloads.
|
||||
#
|
||||
# The names here must line up with the routing map in router.py (M / UNCENSORED).
|
||||
# If you change models, update router.py accordingly (see docs/ROUTING.md).
|
||||
set -u
|
||||
|
||||
MODELS=(
|
||||
# --- general / small ---
|
||||
"qwen3:8b"
|
||||
"qwen3:14b"
|
||||
# --- reasoning / agentic ---
|
||||
"qwen3.6:35b-a3b"
|
||||
"gpt-oss:20b"
|
||||
"glm-4.7-flash"
|
||||
# --- coding ---
|
||||
"qwen3-coder:30b"
|
||||
# --- vision / OCR ---
|
||||
"qwen3-vl:8b"
|
||||
"qwen3-vl:30b-a3b-instruct"
|
||||
# --- multimodal (vision + audio) ---
|
||||
"gemma4:e4b" # ROUTER_AUDIO_MODEL default — needed for /v1/audio/*
|
||||
"gemma4:12b"
|
||||
"gemma4:26b"
|
||||
|
||||
# --- example: a GGUF straight from Hugging Face (see docs/ROUTING.md) ---
|
||||
# "hf.co/USER/REPO:Q4_K_M"
|
||||
)
|
||||
|
||||
ok=(); fail=(); i=0; total=${#MODELS[@]}
|
||||
for m in "${MODELS[@]}"; do
|
||||
i=$((i+1))
|
||||
echo "=== [$i/$total] pulling $m ==="
|
||||
if ollama pull "$m"; then ok+=("$m"); else echo "!! failed: $m"; fail+=("$m"); fi
|
||||
done
|
||||
|
||||
echo ""; echo "done. ${#ok[@]}/$total succeeded."
|
||||
[ ${#fail[@]} -gt 0 ] && { echo "failed:"; printf ' - %s\n' "${fail[@]}"; }
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# One-time setup: create the Python 3.12 venv and install LiteLLM + Pillow.
|
||||
# The pre-router itself needs no venv (stdlib only); this is for the backend proxy.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
PY="${PYTHON:-python3.12}"
|
||||
if ! command -v "$PY" >/dev/null 2>&1; then
|
||||
# common macOS Homebrew fallback
|
||||
[ -x /opt/homebrew/opt/python@3.12/bin/python3.12 ] && PY=/opt/homebrew/opt/python@3.12/bin/python3.12
|
||||
fi
|
||||
command -v "$PY" >/dev/null 2>&1 || { echo "Need Python 3.12. Set \$PYTHON, or:"; \
|
||||
echo " macOS: brew install python@3.12"; echo " Linux: install python3.12"; exit 1; }
|
||||
|
||||
echo ">> using $($PY --version) at $(command -v "$PY" 2>/dev/null || echo "$PY")"
|
||||
[ -d .venv ] || "$PY" -m venv .venv
|
||||
.venv/bin/pip install -q --upgrade pip
|
||||
.venv/bin/pip install -q -r requirements.txt
|
||||
.venv/bin/python -c "import litellm, PIL" && echo ">> deps OK (litellm, pillow)"
|
||||
echo ""
|
||||
echo "Next:"
|
||||
echo " ./scripts/pull-models.sh # pull a model fleet (edit the list first)"
|
||||
echo " ./run.sh # start LiteLLM + router"
|
||||
Reference in New Issue
Block a user