#!/bin/sh -e
#
# ollama-ask - ask local llm
# dependencies: ollama | jq

MODEL=${MODEL:-"$(ollama-current)"}
SYSTEM=${SYSTEM:-/no_think /codding}

PROMPT="$*"

jq --null-input --compact-output --arg model "${MODEL}" \
  --arg prompt "${PROMPT}" --arg system "${SYSTEM}" \
  '{model: $model, prompt: $prompt, system: $system, stream: false}' \
  | curl -s http://localhost:11434/api/generate \
    -H "Content-Type: application/json" \
    -d @- \
  | jq --raw-output '.response // "⚠️ Empty response or model error"' \
  | sed '/<think>/,/<\/think>/d'
