From 08d5fbdabc7fc0cc6b504103452b3a838c2d06e0 Mon Sep 17 00:00:00 2001 From: anaxios Date: Wed, 7 Aug 2024 03:48:26 -0700 Subject: [PATCH] Added spinner animation to indicate AI processing and improved error handling for API request --- aicommit_groq | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/aicommit_groq b/aicommit_groq index 1f1f4b3..715122a 100755 --- a/aicommit_groq +++ b/aicommit_groq @@ -4,10 +4,21 @@ set -eu set -o pipefail ARGS=("${@-}") +TMP_FILE="/tmp/aicommit" pushd "$(pwd)" >/dev/null || exit 1 -TMP_FILE="/tmp/aicommit" +spin() { + echo "${@}" + while true; do + spinner=('-' '\' '|' '/') + for i in "${spinner[@]}"; do + echo -ne "\r${i}" + sleep .05 + done + done + echo "" +} if [[ -z ${GROQ_API_KEY} ]]; then echo "API key not set." @@ -31,7 +42,8 @@ message=$( .stream = false | .stop = null" ) - +spin "AI is thinking..." & +SPINNER="$!" curl -s "https://api.groq.com/openai/v1/chat/completions" \ -X POST \ -H "Content-Type: application/json" \ @@ -40,8 +52,10 @@ curl -s "https://api.groq.com/openai/v1/chat/completions" \ if [[ 0 -ne $? ]]; then echo "Failed to get response." + kill "${SPINNER}" exit 1 fi +kill "${SPINNER}" git commit -e -m "$(cat ${TMP_FILE})" && rm ${TMP_FILE}