Compare commits

..

No commits in common. "2268f9e4012f54ebd40ca229c64b7af0d65975fa" and "43b79b2914b2ff6563c1aa05e755eb80f37208f2" have entirely different histories.

3 changed files with 79 additions and 61 deletions

View File

@ -19,15 +19,6 @@ To use Aicommit, you need to have the following tools installed:
```bash ```bash
export GIT_EDITOR="<path/to/>aicommit" export GIT_EDITOR="<path/to/>aicommit"
``` ```
Optionally you can add the `--groq` flag to use the Groq API.
```bash
export GROQ_API_KEY=<groq-api-key>
```
```bash
export GIT_EDITOR="<path/to/>aicommit --groq"
```
3. **Use Git as normal**: Once configured, you can use Git as you normally would. When you run `git commit`, Aicommit will generate a draft commit message using RayAI, which will then be loaded into your default editor for review and editing. 3. **Use Git as normal**: Once configured, you can use Git as you normally would. When you run `git commit`, Aicommit will generate a draft commit message using RayAI, which will then be loaded into your default editor for review and editing.

View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash #!/bin/bash
set -e set -e
ARGS=("${@-}")
TMP_FILE="/tmp/aicommit_tmp" TMP_FILE="/tmp/aicommit_tmp"
system=$( system=$(
@ -8,12 +10,7 @@ system=$(
You are an expert programmer that values clear, unambiguous communication and are specialized in generating concise and informative git commit messages. 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. Only reply with the commit message and nothing else.
Give description for every change. Give detail for every change in the diff.
Do not include quotes from the diff.
Description should not include a reason only a description.
Description should be one sentence per difference.
Do not include urls.
Do not include headings. for example: 'URLS:'
EOF EOF
) )
@ -23,55 +20,29 @@ if ! diff=$(git diff --cached); then
exit 1 exit 1
fi fi
message_cat="${system} diff: ${diff}"
message=$(
jq -n \
".message = $(jq -R -s '@json' <<<"${message_cat}")"
)
echo "" echo ""
echo "Please wait for AI reponse..." echo "Please wait for AI reponse..."
if [[ "--groq" == "$1" ]]; then if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then
shift
message=$(
jq -n \
".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 |
.top_p = 1 |
.stream = false |
.stop = null"
)
curl -s "https://api.groq.com/openai/v1/chat/completions" \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${GROQ_API_KEY}" \
-d "${message}" | jq -r '.choices[0].message.content | gsub("\""; "")' >"${TMP_FILE}"
if [[ 0 -ne $? ]]; then
echo "Failed to get response."
exit 1
fi
else
message_cat="${system} diff: ${diff}"
message=$(
jq -n \
".message = $(jq -R -s '@json' <<<"${message_cat}")"
)
if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then
echo "Failed to reset conversation." echo "Failed to reset conversation."
exit 1 exit 1
fi fi
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" \
-d "${message}" | jq -r '.content | gsub("\""; "")' >"${TMP_FILE}" -d "${message}" | jq -r '.content | gsub("\""; "")' >"${TMP_FILE}"
if [[ 0 -ne $? ]]; then if [[ 0 -ne $? ]]; then
echo "Failed to get response." echo "Failed to get response."
exit 1 exit 1
fi
fi fi
cat ".git/COMMIT_EDITMSG" >>"${TMP_FILE}" cat ".git/COMMIT_EDITMSG" >>"${TMP_FILE}"
@ -79,4 +50,4 @@ cat "${TMP_FILE}" >".git/COMMIT_EDITMSG"
rm "${TMP_FILE}" rm "${TMP_FILE}"
"${EDITOR}" "${@-}" "${EDITOR}" "$@"

56
aicommit_groq Executable file
View File

@ -0,0 +1,56 @@
#!/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
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
fi
message=$(
jq -n \
".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 |
.top_p = 1 |
.stream = false |
.stop = null"
)
# trunk-ignore(shellcheck/SC2312)
curl -s "https://api.groq.com/openai/v1/chat/completions" \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${GROQ_API_KEY}" \
-d "${message}" | jq -r '.choices[0].message.content | gsub("\""; "")' >"${TMP_FILE}"
if [[ 0 -ne $? ]]; then
echo "Failed to get response."
exit 1
fi
git commit -e -m "$(cat ${TMP_FILE})" && rm ${TMP_FILE}
popd >/dev/null || exit 1