You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
diff=$(echo $diff| sed 's/\\/\\\\/g'| sed 's/"/\\"/g'| sed 's/\n/\\n/g')
24
-
25
-
# Prepare the Gemini API request
26
-
# gemini_request='{
27
-
# "contents":[{"parts":[{"text": "Write a git commit message title (no more than 72 characters total) for the following git diff: '"$diff"' Do not include any other text in the response."}]}],
"prompt": "Write a git commit message title (no more than 72 characters total) for the following git diff: '"$diff"' Do not include any other text in the response."
39
-
}'
40
-
41
-
# Request a commit message from Ollama Gemma3n local API
# If the commit message is empty, retry the request
45
-
if [ -z"$commit_message" ];then
46
-
commit_message=$(curl -s \
47
-
-H 'Content-Type: application/json' \
48
-
-d "$gemma_request" \
49
-
-X POST "http://localhost:11434/api/generate" \
50
-
| jq -r '.response'
51
-
)
52
-
fi
20
+
# Default model (change if desired)
21
+
MODEL="mistral"
22
+
23
+
# Prepare the prompt
24
+
PROMPT=$(printf "You are an expert software engineer.\n\nYour job is to generate a short, commit message from the following git diff.\nNo more than 72 characters total.\nOnly return the commit message. Do not include any other text.\n\nGit diff:\n%s""$diff")
25
+
26
+
# Run the model and capture output
27
+
COMMIT_MSG=$(echo "$PROMPT"| ollama run "$MODEL")
53
28
54
-
# If the commit message is still empty, exit with an error
55
-
if [ -z"$commit_message" ];then
56
-
echo"Error: Ollama API request for commit message failed. Please try again."
29
+
# If the commit message is empty, exit with an error
30
+
if [ -z"$COMMIT_MSG" ];then
31
+
echo"Error: Commit message is empty. Please check the diff and try again."
57
32
exit 1
58
33
fi
59
34
60
-
# # Request and parse the commit message from Gemini API
61
-
# commit_message=$(curl -s \
62
-
# -H 'Content-Type: application/json' \
63
-
# -d "$gemini_request" \
64
-
# -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
65
-
# | jq -r '.candidates[0].content.parts[0].text'
66
-
# )
67
-
68
-
# If the commit message is empty, retry the request
69
-
# if [ -z "$commit_message" ]; then
70
-
# commit_message=$(curl -s \
71
-
# -H 'Content-Type: application/json' \
72
-
# -d "$gemini_request" \
73
-
# -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
74
-
# | jq -r '.candidates[0].content.parts[0].text'
75
-
# )
76
-
# fi
77
-
78
35
# Clean up commit message formatting - remove #, ```, period . at the end of response
79
-
commit_message=$(echo $commit_message| sed 's/#//g'| sed 's/```//g'| sed 's/Commit message title://g'| sed 's/Commit message summary://g'| sed 's/\.//g')
36
+
commit_message=$(echo $COMMIT_MSG| sed 's/#//g'| sed 's/```//g'| sed 's/Commit message title://g'| sed 's/Commit message summary://g'| sed 's/\.//g')
80
37
81
-
#Print the commit message
38
+
#Echo the commit message
82
39
echo$commit_message
83
40
84
-
# # If the Gemini retry request fails, exit
85
-
# if [ -z "$commit_message" ]; then
86
-
# echo "Error: API request for commit message failed. Please try again."
87
-
# exit 1
88
-
# fi
89
-
90
-
# export COMMIT_MESSAGE="$commit_message"
91
-
# export TICKET="$ticket"
92
-
# # Prepare and execute commit command, remove -S to commit without signing
93
-
# if [ -z "$ticket" ]; then
94
-
# expect <<'EOF'
95
-
# spawn git commit -S -m "$env(COMMIT_MESSAGE)"
96
-
# expect "Enter passphrase for \"/Users/wscholl/.ssh/id_ed25519\":"
0 commit comments