Update git-commit-ai script: remove endpoint, use aichat for model selection

- Replace hardcoded endpoint with aichat for model selection
- Remove system_message variable and its usage in query
- Use aichat command for generating commit message instead of curl
This commit is contained in:
Sam 2024-06-22 15:12:31 +01:00
parent 5b65d7d5b1
commit aef3c1c1ce
1 changed files with 4 additions and 28 deletions

View File

@ -31,48 +31,24 @@
# Usage: ./git-commit-ai --git-diff-commands --model # Usage: ./git-commit-ai --git-diff-commands --model
# #
# #
endpoint="10.0.10.100:11434"
diff=$(git diff "$@" ) diff=$(git diff "$@" )
[ -z "$diff" ] && echo "No diff provided. Did you stage the changes?" && exit 1 [ -z "$diff" ] && echo "No diff provided. Did you stage the changes?" && exit 1
tokens=$(echo "$diff" | tiktoken-cli) tokens=$(echo "$diff" | tiktoken-cli)
echo -e "\n\nEstimated tokens: $tokens\n\n" echo -e "\n\nEstimated tokens: $tokens\n\n"
choose_model() { choose_model() {
models_response=$(curl http://$endpoint/api/tags) models=$(${pkgs.aichat}/bin/aichat --list-models)
model=$(echo "$models_response" | jq -r '..|.model? // empty' | fzf | sed 's/:latest$//') model=$(echo "$models" | fzf)
} }
choose_model choose_model
system_message="""
You are a git commit generator. You will be provided with a git diff file.
Your role is to create a concise commit message that outlines all of the
most relevant and impactful changes in the diff. You only output a commit
message, do not write anything else not related to the commit. Use
imperative mood for you writing style.
Your message should include a short summary in the first line followed by
more detailed descriptions of the changes on subsequent lines.
The first line summary should be no more than 70 characters, not end with a
period, and a blank line should separate the summary from the body of the
message.
There should only be 1 summary line, and 1 body with the description.
The body should include no more than 3 bullet points with more detailed
descriptions of the files and functions that have been modified.
Do not output any code.
"""
query=$(jq -n --arg model "$model" --arg system_message "$system_message" --arg prompt "$diff" '{model: $model, system: $system_message, prompt: $prompt, stream: false}')
git config commit.template ".git/gitmessage" git config commit.template ".git/gitmessage"
redo="" redo=""
while true while true
do do
[ -z "$redo" ] && echo "Using model: $model" && commit_message=$(curl -s http://$endpoint/api/generate -H "Content-Type: application/json" -d "$query" | jq -r '.response') [ -z "$redo" ] && echo "Using model: $model" && commit_message=$(${pkgs.aichat}/bin/aichat --model "$model" --role "git_commit" "$diff")
echo "" echo ""
echo "Message:" echo "Message:"