#!/usr/bin/env bash MODEL="llama3.2" OLLAMA_URL="http://localhost:11434/api/chat" echo "Chatting with Ollama ($MODEL)." echo "Type 'exit' or 'quit' to stop." echo MESSAGES='[]' while true; do read -rp "You: " USER_INPUT if [[ "$USER_INPUT" == "exit" || "$USER_INPUT" == "quit" ]]; then echo "Goodbye!" break fi MESSAGES=$(echo "$MESSAGES" | jq \ --arg content "$USER_INPUT" \ '. + [{"role":"user","content":$content}]') RESPONSE=$(curl -s "$OLLAMA_URL" \ -H "Content-Type: application/json" \ -d "$(jq -n \ --arg model "$MODEL" \ --argjson messages "$MESSAGES" \ '{ model: $model, messages: $messages, stream: false }')") ASSISTANT_REPLY=$(echo "$RESPONSE" | jq -r '.message.content') echo echo "Ollama: $ASSISTANT_REPLY" echo MESSAGES=$(echo "$MESSAGES" | jq \ --arg content "$ASSISTANT_REPLY" \ '. + [{"role":"assistant","content":$content}]') done