commit 95aa730114875ef09b4d0085573b1d6db50d95d8 Author: anaxios Date: Tue Aug 6 19:53:06 2024 -0700 first diff --git a/aicommit b/aicommit new file mode 100755 index 0000000..c188400 --- /dev/null +++ b/aicommit @@ -0,0 +1,39 @@ +#!/bin/bash + +pushd $(pwd) "$@" >/dev/null + +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." + +diff=$(git diff --cached) +if [[ 0 -ne $? ]]; then + echo "Failed to get diff." + exit 1 +fi + +message_cat="$system diff: $diff" + +message=$(jq -n \ + ".message = $(jq -R -s '@json' <<< "$message_cat")" +) + +curl -s -X POST https://infer.x64.world/reset-conversation "$@">/dev/null +if [[ 0 -ne $? ]]; 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 + +git commit -e -m "$(cat ${TMP_FILE})" && rm ${TMP_FILE} + +popd "$@" >/dev/null diff --git a/aicommit_groq b/aicommit_groq new file mode 100755 index 0000000..9541caf --- /dev/null +++ b/aicommit_groq @@ -0,0 +1,37 @@ +#!/bin/bash +pushd $(pwd) "$@" >/dev/null + +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." + +diff=$(git diff --cached) +if [[ 0 -ne $? ]]; 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" +) + +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 \ No newline at end of file