Title: Update GROQ API request to match official documentation

Content: Updated curl command and removed unnecessary code for setting up spinner.
This commit is contained in:
ilguappo 2024-08-07 04:21:13 -07:00
parent 624861e320
commit ab5738d14e
2 changed files with 4 additions and 21 deletions

View File

@ -5,7 +5,6 @@ set -e
ARGS=("${@-}") ARGS=("${@-}")
TMP_FILE="/tmp/aicommit" TMP_FILE="/tmp/aicommit"
system=$( system=$(
cat - <<EOF cat - <<EOF
@ -18,24 +17,11 @@ EOF
pushd "$(pwd)" >/dev/null || exit 1 pushd "$(pwd)" >/dev/null || exit 1
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 if [[ -z ${GROQ_API_KEY} ]]; then
echo "API key not set." echo "API key not set."
exit 1 exit 1
fi fi
if ! diff=$(git diff --cached); then if ! diff=$(git diff --cached); then
echo "Failed to get diff." echo "Failed to get diff."
exit 1 exit 1
@ -51,8 +37,7 @@ message=$(
.stream = false | .stream = false |
.stop = null" .stop = null"
) )
spin "AI is thinking..." &
SPINNER="$!"
curl -s "https://api.groq.com/openai/v1/chat/completions" \ curl -s "https://api.groq.com/openai/v1/chat/completions" \
-X POST \ -X POST \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
@ -61,10 +46,8 @@ curl -s "https://api.groq.com/openai/v1/chat/completions" \
if [[ 0 -ne $? ]]; then if [[ 0 -ne $? ]]; then
echo "Failed to get response." echo "Failed to get response."
kill "${SPINNER}"
exit 1 exit 1
fi fi
kill "${SPINNER}"
git commit -e -m "$(cat ${TMP_FILE})" && rm ${TMP_FILE} git commit -e -m "$(cat ${TMP_FILE})" && rm ${TMP_FILE}