From 48f99123f483b5d3ae1fa78f91488f2407ca2f79 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 16 Dec 2025 16:25:08 +0000 Subject: [PATCH] Add bash_testing.sh --- bash_testing.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 bash_testing.sh diff --git a/bash_testing.sh b/bash_testing.sh new file mode 100644 index 0000000..8935e6a --- /dev/null +++ b/bash_testing.sh @@ -0,0 +1,45 @@ +#!/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