#!/bin/sh -e
#
# dependencies: gum

ask_ai() {
  PROMPT=$(gum input --width 80 --placeholder "prompt")

  if [ -z "${PROMPT}" ]; then
    exit 0
  fi

  gum style --foreground 212 "> ${PROMPT}"

  RESULT=$(
    gum spin -s line --title "Asking ai..." --show-output -- curl -sS http://localhost:11434/api/chat \
      -H "Content-Type: application/json" \
      -d '{
      "model": "olmo2",
      "messages": [{"role": "user", "content": "'"${PROMPT}"'"}]
    }' | jq ".choices[0].message.content"
  )

  printf '%s' "${RESULT}" | glow
}

while true; do
  ask_ai
done
