Compare commits

...

10 Commits

Author SHA1 Message Date
455ae71cd3 Removed unnecessary line break and improved error message. 2024-08-07 07:07:58 -07:00
6fa213550d Add pipefail option to set command to prevent pipes from hiding errors, improve script reliability 2024-08-07 04:40:22 -07:00
e0ee195fca Content: Replaced custom spinner with curl command and removed unnecessary code for setting up spinner. 2024-08-07 04:33:31 -07:00
7de04c06c9 Title: Update GROQ API request to match official documentation
Content: Fixed JSON formatting and removed unnecessary comment.
URL: https://console.groq.com/docs/
2024-08-07 04:32:23 -07:00
ab5738d14e Title: Update GROQ API request to match official documentation
Content: Updated curl command and removed unnecessary code for setting up spinner.
2024-08-07 04:21:13 -07:00
624861e320 Refactor aicommit_groq script: extract system message to a heredoc, remove redundant variable assignment, and improve code organization 2024-08-07 04:12:18 -07:00
cf655b7202 Title: Fix typo in system message
Content: Removed unnecessary newline and changed -in back to in in the system message definition.
2024-08-07 04:09:28 -07:00
41dc5665b4 Title: Improve system message definition
Content: Replaced string concatenation with a here document to improve readability and maintainability. Fixed trailing whitespace by adding a newline at the end of the last line.
2024-08-07 04:08:00 -07:00
74909d05f4 Title: Update system message
Content: Changed system message to include detail about every change in the diff for better clarity and precision
2024-08-07 03:58:46 -07:00
c72a7835da Title: Improve script robustness
Content: Switch from set -eu to set -e for more robust error handling
2024-08-07 03:54:16 -07:00
2 changed files with 24 additions and 41 deletions

View File

@ -1,10 +1,18 @@
#!/bin/bash
set -eu
set -e
ARGS=("${@-}")
TMP_FILE="/tmp/aicommit"
system="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."
system=$(
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.
Give detail for every change in the diff.
EOF
)
pushd "$(pwd)" >/dev/null
@ -21,18 +29,6 @@ hasFlag() {
echo 'false'
}
spin() {
echo "${@}"
while true; do
spinner=('-' '\' '|' '/')
for i in "${spinner[@]}"; do
echo -ne "\r${i}"
sleep .05
done
done
echo ""
}
if ! diff=$(git diff --cached); then
echo "Failed to get diff."
exit 1
@ -48,18 +44,12 @@ message=$(
# trunk-ignore(shellcheck/SC2091)
# trunk-ignore(shellcheck/SC2310)
if $(hasFlag -r --reset); then
spin "resetting AI history." &
SPINNER="$!"
if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then
echo "Failed to reset conversation."
kill ${SPINNER}
exit 1
fi
kill "${SPINNER}"
fi
spin "AI is thinking." &
SPINNER="$!"
curl -s "https://infer.x64.world/chat" \
-X POST \
-H "Content-Type: application/json" \
@ -67,11 +57,9 @@ curl -s "https://infer.x64.world/chat" \
# trunk-ignore(shellcheck/SC2181)
if [[ 0 -ne $? ]]; then
kill "${SPINNER}"
echo "Failed to get response."
exit 1
fi
kill "${SPINNER}"
git commit -e -m "$(cat "${TMP_FILE}")" && rm "${TMP_FILE}"

View File

@ -1,31 +1,28 @@
#!/bin/bash
set -e
set -o pipefail
ARGS=("${@-}")
TMP_FILE="/tmp/aicommit"
pushd "$(pwd)" >/dev/null || exit 1
system=$(
cat - <<EOF
spin() {
echo "${@}"
while true; do
spinner=('-' '\' '|' '/')
for i in "${spinner[@]}"; do
echo -ne "\r${i}"
sleep .05
done
done
echo ""
}
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.
Give detail for every change in the diff.
EOF
)
pushd "$(pwd)" >/dev/null || exit 1
if [[ -z ${GROQ_API_KEY} ]]; then
echo "API key not set."
exit 1
fi
system="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."
if ! diff=$(git diff --cached); then
echo "Failed to get diff."
exit 1
@ -33,7 +30,7 @@ fi
message=$(
jq -n \
".messages = [{role: \"system\", content: $(jq -R -s '@json' <<<"$system")}, {role: \"user\", content: $(jq -R -s '@json' <<<"$diff")}] |
".messages = [{role: \"system\", content: $(jq -R -s '@json' <<<"${system}")}, {role: \"user\", content: $(jq -R -s '@json' <<<"${diff}")}] |
.model = \"llama-3.1-70b-versatile\" |
.temperature = 1 |
.max_tokens = 1024 |
@ -41,8 +38,8 @@ message=$(
.stream = false |
.stop = null"
)
spin "AI is thinking..." &
SPINNER="$!"
# trunk-ignore(shellcheck/SC2312)
curl -s "https://api.groq.com/openai/v1/chat/completions" \
-X POST \
-H "Content-Type: application/json" \
@ -51,10 +48,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}