about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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