Fully automated setup: downloads GGUF, loads model, tests inference

Setup script now:
1. Generates API key
2. Starts Docker containers
3. Downloads GGUF from mortdec.ai automatically (~5.3GB)
4. Creates Ollama model with correct chat template
5. Runs test inference
6. Prints connection details for Seth

Matt just runs ./setup.sh — no manual file copying.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-20 19:33:39 -04:00
parent c5865feb35
commit df9f623943
2 changed files with 75 additions and 30 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ services:
- "127.0.0.1:11434:11434" # Only accessible to gateway, not exposed - "127.0.0.1:11434:11434" # Only accessible to gateway, not exposed
volumes: volumes:
- ollama-data:/root/.ollama - ollama-data:/root/.ollama
- ./models:/models - ./models:/models:ro
devices: devices:
- /dev/kfd:/dev/kfd - /dev/kfd:/dev/kfd
- /dev/dri:/dev/dri - /dev/dri:/dev/dri
+74 -29
View File
@@ -1,10 +1,15 @@
#!/bin/bash #!/bin/bash
# Quick setup for Mortdecai Gateway # Mortdecai Gateway — fully automated setup
# Run this after cloning the repo # Just run: ./setup.sh
# Everything downloads and configures automatically.
set -e set -e
MODEL_URL="${MODEL_URL:-https://mortdec.ai/dl/m4gguf/mortdecai-v4.gguf}"
MODEL_NAME="mortdecai-v4"
echo "=== Mortdecai Gateway Setup ===" echo "=== Mortdecai Gateway Setup ==="
echo ""
# Generate API key if not set # Generate API key if not set
if [ ! -f .env ]; then if [ ! -f .env ]; then
@@ -20,30 +25,52 @@ EOF
echo "Saved to .env" echo "Saved to .env"
else else
echo ".env already exists" echo ".env already exists"
KEY=$(grep API_KEY .env | cut -d= -f2)
fi fi
# Start containers # Start containers
echo ""
echo "Starting containers..." echo "Starting containers..."
docker compose up -d docker compose up -d
# Wait for Ollama to be ready # Wait for Ollama to be ready
echo "Waiting for Ollama..." echo "Waiting for Ollama to start..."
for i in $(seq 1 30); do for i in $(seq 1 60); do
if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
echo "Ollama is ready" echo "Ollama is ready"
break break
fi fi
if [ $i -eq 60 ]; then
echo "ERROR: Ollama failed to start after 2 minutes"
echo "Check: docker logs mortdecai-ollama"
exit 1
fi
sleep 2 sleep 2
done done
# Load the model if GGUF exists # Check if model already loaded
if ls models/*.gguf 1>/dev/null 2>&1; then LOADED=$(curl -s http://localhost:11434/api/tags 2>/dev/null | python3 -c "import sys,json; print('yes' if any('$MODEL_NAME' in m['name'] for m in json.load(sys.stdin).get('models',[])) else 'no')" 2>/dev/null || echo "no")
GGUF=$(ls models/*.gguf | head -1)
MODEL_NAME=$(basename "$GGUF" .gguf | tr '[:upper:]' '[:lower:]')
echo "Loading model from $GGUF..."
cat > /tmp/Modelfile << MEOF if [ "$LOADED" = "yes" ]; then
FROM /models/$(basename $GGUF) echo "Model $MODEL_NAME already loaded"
else
# Download GGUF
mkdir -p models
GGUF_PATH="models/${MODEL_NAME}.gguf"
if [ ! -f "$GGUF_PATH" ]; then
echo ""
echo "Downloading model (~5.3 GB)..."
echo "Source: $MODEL_URL"
curl -L -o "$GGUF_PATH" "$MODEL_URL" --progress-bar
echo "Download complete"
else
echo "GGUF already downloaded"
fi
# Create Modelfile
cat > models/Modelfile << 'MEOF'
FROM /models/mortdecai-v4.gguf
TEMPLATE """{{- if .Messages }} TEMPLATE """{{- if .Messages }}
{{- if or .System .Tools }}<|im_start|>system {{- if or .System .Tools }}<|im_start|>system
{{- if .System }} {{- if .System }}
@@ -51,11 +78,11 @@ TEMPLATE """{{- if .Messages }}
{{- end }} {{- end }}
<|im_end|> <|im_end|>
{{ end }} {{ end }}
{{- range \$m := .Messages }} {{- range $m := .Messages }}
{{- if eq \$m.Role "user" }}<|im_start|>user {{- if eq $m.Role "user" }}<|im_start|>user
{{ \$m.Content }}<|im_end|> {{ $m.Content }}<|im_end|>
{{- else if eq \$m.Role "assistant" }}<|im_start|>assistant {{- else if eq $m.Role "assistant" }}<|im_start|>assistant
{{ \$m.Content }}<|im_end|> {{ $m.Content }}<|im_end|>
{{- end }} {{- end }}
{{- end }}<|im_start|>assistant {{- end }}<|im_start|>assistant
{{ end }}""" {{ end }}"""
@@ -64,22 +91,40 @@ PARAMETER stop <|im_start|>
PARAMETER temperature 0.7 PARAMETER temperature 0.7
MEOF MEOF
docker exec mortdecai-ollama ollama create mortdecai-v4 -f /tmp/Modelfile echo "Loading model into Ollama..."
echo "Model loaded as mortdecai-v4" docker exec mortdecai-ollama ollama create "$MODEL_NAME" -f /models/Modelfile
echo "Model loaded as $MODEL_NAME"
fi
# Quick test
echo ""
echo "Running test inference..."
RESULT=$(curl -s http://localhost:8434/api/chat \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d "{\"model\": \"$MODEL_NAME\", \"messages\": [{\"role\": \"user\", \"content\": \"say hello\"}], \"stream\": false}" 2>/dev/null)
if echo "$RESULT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['message']['content'][:80])" 2>/dev/null; then
echo "Test passed!"
else else
echo "No GGUF found in models/ — place your GGUF file there and run:" echo "Test inference returned unexpected result (model may still be loading)"
echo " docker exec mortdecai-ollama ollama create mortdecai-v4 -f Modelfile" echo "Try again in a minute: curl -s http://localhost:8434/health"
fi fi
echo "" echo ""
echo "=== Setup Complete ===" echo "========================================="
echo "Dashboard: http://localhost:8434/dashboard" echo " Mortdecai Gateway is ready!"
echo "API Key: $(grep API_KEY .env | cut -d= -f2)" echo "========================================="
echo "" echo ""
echo "Test: curl -s http://localhost:8434/health" echo " Dashboard: http://localhost:8434/dashboard"
echo " Health: http://localhost:8434/health"
echo " API Key: $KEY"
echo "" echo ""
echo "To use from remote:" echo " Send this to Seth:"
echo " curl -X POST http://YOUR_IP:8434/api/chat \\" echo " - Your public IP"
echo " -H 'Authorization: Bearer YOUR_API_KEY' \\" echo " - Port: 8434"
echo " -H 'Content-Type: application/json' \\" echo " - API Key: $KEY"
echo " -d '{\"model\": \"mortdecai-v4\", \"messages\": [{\"role\": \"user\", \"content\": \"test\"}]}'" echo ""
echo " To stop: docker compose down"
echo " To start: docker compose up -d"
echo "========================================="