From a271e5624e41a74f8d650ca52f06e65cfffb0450 Mon Sep 17 00:00:00 2001 From: anaxios Date: Fri, 9 Aug 2024 12:34:29 -0700 Subject: [PATCH] Changed the shebang line from `#!/bin/bash` to `#!/usr/bin/env bash`. Removed the `aicommit_groq` script and deleted the file. Updated the `EDITOR` command to use the `ARGS` array. Moved groq config into aicommit. --- aicommit | 77 ++++++++++++++++++++++++++++++++++++--------------- aicommit_groq | 56 ------------------------------------- 2 files changed, 54 insertions(+), 79 deletions(-) delete mode 100755 aicommit_groq diff --git a/aicommit b/aicommit index 4bed12f..6c7ace9 100755 --- a/aicommit +++ b/aicommit @@ -1,8 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash set -e -ARGS=("${@-}") - TMP_FILE="/tmp/aicommit_tmp" system=$( @@ -10,7 +8,12 @@ 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. -Give detail for every change in the diff. +Give description for every change. +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 ) @@ -20,29 +23,55 @@ if ! diff=$(git diff --cached); then exit 1 fi -message_cat="${system} diff: ${diff}" +if [[ "--groq" == "$1" ]]; then + shift -message=$( - jq -n \ - ".message = $(jq -R -s '@json' <<<"${message_cat}")" -) + 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" + ) -echo "" -echo "Please wait for AI reponse..." + 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 ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then - echo "Failed to reset conversation." - exit 1 -fi + if [[ 0 -ne $? ]]; then + echo "Failed to get response." + exit 1 + fi +else + message_cat="${system} diff: ${diff}" -curl -s "https://infer.x64.world/chat" \ - -X POST \ - -H "Content-Type: application/json" \ - -d "${message}" | jq -r '.content | gsub("\""; "")' >"${TMP_FILE}" + message=$( + jq -n \ + ".message = $(jq -R -s '@json' <<<"${message_cat}")" + ) -if [[ 0 -ne $? ]]; then - echo "Failed to get response." - exit 1 + echo "" + echo "Please wait for AI reponse..." + + if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then + echo "Failed to reset conversation." + exit 1 + fi + + curl -s "https://infer.x64.world/chat" \ + -X POST \ + -H "Content-Type: application/json" \ + -d "${message}" | jq -r '.content | gsub("\""; "")' >"${TMP_FILE}" + + if [[ 0 -ne $? ]]; then + echo "Failed to get response." + exit 1 + fi fi cat ".git/COMMIT_EDITMSG" >>"${TMP_FILE}" @@ -50,4 +79,6 @@ cat "${TMP_FILE}" >".git/COMMIT_EDITMSG" rm "${TMP_FILE}" -"${EDITOR}" "$@" +ARGS=("${@-}") + +"${EDITOR}" "${ARGS[@]}" diff --git a/aicommit_groq b/aicommit_groq deleted file mode 100755 index 5ba92bd..0000000 --- a/aicommit_groq +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -set -e -set -o pipefail - -ARGS=("${@-}") -TMP_FILE="/tmp/aicommit" - -system=$( - cat - </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