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

View File

@ -1,31 +1,28 @@
#!/bin/bash #!/bin/bash
set -e set -e
set -o pipefail
ARGS=("${@-}") ARGS=("${@-}")
TMP_FILE="/tmp/aicommit" TMP_FILE="/tmp/aicommit"
pushd "$(pwd)" >/dev/null || exit 1 system=$(
cat - <<EOF
spin() { You are an expert programmer that values clear, unambiguous communication and are specialized in generating concise and informative git commit messages.
echo "${@}" Only reply with the commit message and nothing else.
while true; do Give detail for every change in the diff.
spinner=('-' '\' '|' '/')
for i in "${spinner[@]}"; do EOF
echo -ne "\r${i}" )
sleep .05
done pushd "$(pwd)" >/dev/null || exit 1
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
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 if ! diff=$(git diff --cached); then
echo "Failed to get diff." echo "Failed to get diff."
exit 1 exit 1
@ -33,7 +30,7 @@ fi
message=$( message=$(
jq -n \ 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\" | .model = \"llama-3.1-70b-versatile\" |
.temperature = 1 | .temperature = 1 |
.max_tokens = 1024 | .max_tokens = 1024 |
@ -41,8 +38,8 @@ message=$(
.stream = false | .stream = false |
.stop = null" .stop = null"
) )
spin "AI is thinking..." &
SPINNER="$!" # trunk-ignore(shellcheck/SC2312)
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" \
@ -51,10 +48,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}