Created
May 30, 2025 02:00
-
-
Save brain90/99383eb74217c2a090545aa10e8c16e4 to your computer and use it in GitHub Desktop.
Bash Ollama LLM Simple Interfaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MODEL="wizard-vicuna-uncensored:latest" | |
API_URL="asupkeun-api-endpoint" | |
HISTORY="[]" | |
while true; do | |
read -p "You: " USER_INPUT | |
[[ -z "$USER_INPUT" ]] && break | |
HISTORY=$(jq -n --argjson h "$HISTORY" --arg m "$USER_INPUT" \ | |
'$h + [{"role":"user","content":$m}]') | |
FULL_REPLY="" | |
while IFS= read -r line; do | |
content=$(echo "$line" | jq -r --exit-status 'select(.message.content != null) | .message.content' 2>/dev/null) | |
if [[ -n "$content" ]]; then | |
printf "%s" "$content" | |
FULL_REPLY+="$content" | |
fi | |
done < <(curl -sN "$API_URL" \ | |
-H "Content-Type: application/json" \ | |
-d "{ | |
\"model\": \"$MODEL\", | |
\"messages\": $HISTORY, | |
\"stream\": true | |
}") | |
echo | |
HISTORY=$(jq -n --argjson h "$HISTORY" --arg m "$FULL_REPLY" \ | |
'$h + [{"role":"assistant","content":$m}]') | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment