#!/bin/bash
# Start Gemma 2 9B with MLX

PORT=8083
MODEL="mlx-community/gemma-2-9b-it-4bit"
LOG_FILE="/Users/accusys/momentry_core/logs/gemma2_9b_mlx_8083.log"

# Kill existing process if running
if lsof -i :$PORT > /dev/null 2>&1; then
    OLD_PID=$(lsof -i :$PORT | awk 'NR>1 {print $2}')
    kill $OLD_PID
    sleep 2
fi

# Start MLX server
nohup python3 -m mlx_lm.server \
    --model $MODEL \
    --host 0.0.0.0 \
    --port $PORT \
    > $LOG_FILE 2>&1 &

echo "Gemma 2 9B MLX started on port $PORT"
echo "Log file: $LOG_FILE"
echo "Health check: http://localhost:$PORT/health"
