Compare commits

..

No commits in common. "455ae71cd35a5fa0d66f6400f4b5e1185c1e3ad4" and "1767b2c7371c519e1cd894ab4a6813451722acb5" have entirely different histories.

2 changed files with 41 additions and 24 deletions

View File

@ -1,18 +1,10 @@
#!/bin/bash
set -e
set -eu
ARGS=("${@-}")
TMP_FILE="/tmp/aicommit"
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
)
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."
pushd "$(pwd)" >/dev/null
@ -29,6 +21,18 @@ 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
@ -44,12 +48,18 @@ 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" \
@ -57,9 +67,11 @@ 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,28 +1,31 @@
#!/bin/bash
set -e
set -o pipefail
ARGS=("${@-}")
TMP_FILE="/tmp/aicommit"
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 || 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
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
@ -30,7 +33,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 |
@ -38,8 +41,8 @@ message=$(
.stream = false |
.stop = null"
)
# trunk-ignore(shellcheck/SC2312)
spin "AI is thinking..." &
SPINNER="$!"
curl -s "https://api.groq.com/openai/v1/chat/completions" \
-X POST \
-H "Content-Type: application/json" \
@ -48,8 +51,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}