#!/usr/bin/env bash

OLLAMA_HOST="http://ollama:11434"

IFS=',' read -r -a models_arr <<< "${MODELS}"

## now loop through the above array
for m in "${models_arr[@]}"
do
  curl -s "${OLLAMA_HOST}/api/tags" | jq '.models[].name' | grep ${m} > /dev/null
  if [[ $? -ne 0 ]]
  then
    curl -s "${OLLAMA_HOST}/api/pull" -d "{\"model\": \"${m}\"}"
  else
    echo "${m} already installed"
  fi
done