#!/bin/bash
# Generated by aissemble-oip-deploy
# Start MLServer locally for development/testing

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODELS_DIR="${SCRIPT_DIR}/{{ models_dir }}"

# Check if MLServer is installed
if ! command -v mlserver &> /dev/null; then
    echo "Error: MLServer is not installed or not in PATH"
    echo ""
    echo "To install MLServer, run:"
    echo "  pip install mlserver"
    echo ""
    echo "Or with uv:"
    echo "  uv pip install mlserver"
    echo ""
{% if models %}
    echo "Note: This project uses {{ models | length }} model(s). You may also need to install"
    echo "model-specific runtime packages. See the README.md for details."
    echo ""
{% endif %}
    exit 1
fi

# Verify models directory exists
if [ ! -d "$MODELS_DIR" ]; then
    echo "Error: Models directory not found: $MODELS_DIR"
    exit 1
fi

echo "Starting MLServer..."
echo "  Models directory: $MODELS_DIR"
echo "  Port: {{ port }}"
{% if models %}
echo "  Models:"
{% for model in models %}
echo "    - {{ model.name }}"
{% endfor %}
{% endif %}
echo ""

# Start MLServer
cd "$MODELS_DIR"
exec mlserver start .
