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,7 @@ ARGS=("${@-}")
TMP_FILE="/tmp/aicommit"
system=$(
cat - <<EOF
cat - <<EOF
You are an expert programmer that values clear, unambiguous communication and are specialized in generating concise and informative git commit messages.
Only reply with the commit message and nothing else.
@ -83,4 +83,4 @@ kill "${SPINNER}"
git commit -e -m "$(cat "${TMP_FILE}")" && rm "${TMP_FILE}"
popd >/dev/null
popd >/dev/null

View File

@ -5,9 +5,8 @@ set -e
ARGS=("${@-}")
TMP_FILE="/tmp/aicommit"
system=$(
cat - <<EOF
cat - <<EOF
You are an expert programmer that values clear, unambiguous communication and are specialized in generating concise and informative git commit messages.
Only reply with the commit message and nothing else.
@ -18,24 +17,11 @@ EOF
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
echo "API key not set."
exit 1
fi
if ! diff=$(git diff --cached); then
echo "Failed to get diff."
exit 1
@ -51,8 +37,7 @@ 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" \
@ -61,10 +46,8 @@ 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}