about summary refs log tree commit diff stats
path: root/bash
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-02-23 21:14:42 -0500
committerelioat <elioat@tilde.institute>2025-02-23 21:14:42 -0500
commit3bed0d3550d620217d29626cb0b4354e087f94f2 (patch)
tree737b41573e5f43676c2a98d1755c7cc3dc2dbc1c /bash
parent883bd856bc05ea72239e89ca262941c75c70fefd (diff)
downloadtour-3bed0d3550d620217d29626cb0b4354e087f94f2.tar.gz
*
Diffstat (limited to 'bash')
-rwxr-xr-xbash/sentiment/sentiment41
1 files changed, 41 insertions, 0 deletions
diff --git a/bash/sentiment/sentiment b/bash/sentiment/sentiment
new file mode 100755
index 0000000..432352c
--- /dev/null
+++ b/bash/sentiment/sentiment
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+# Define the prompt as a multi-line variable
+read -r -d '' PROMPT << 'EOF'
+Please analyze this text and rate its sentiment on a scale from -10 (very negative) 
+to +10 (very positive). Provide your rating as a numeric score and as human-readable 
+text. Explain your rating:
+EOF
+
+if ! command -v llm &> /dev/null; then
+    echo "llm could not be found, you'll need to install it to use this program"
+    exit 1
+fi
+
+if ! command -v w3m &> /dev/null; then
+    echo "w3m could not be found, you'll need to install it to use this program"
+    exit 1
+fi
+
+if ! command -v ollama &> /dev/null; then
+    echo "ollama could not be found, you'll need to install it to use this program"
+    exit 1
+fi
+
+if ! ollama list | grep -q "llama3.1:8b"; then
+    echo "ollama is not running, you'll need to start it to use this program"
+    exit 1
+fi
+
+if [ -z "$1" ]; then
+    echo "Usage: ./sentiment <url> [model]"
+    exit 1
+fi
+
+# Check if a model name is provided
+MODEL_OPTION=""
+if [ ! -z "$2" ]; then
+    MODEL_OPTION="-m $2"
+fi
+
+w3m -dump "$1" | llm $MODEL_OPTION "$PROMPT"
\ No newline at end of file