Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e5d9fae

Browse files
Updated to use Modelfile and fine tuning, much more accurate
1 parent 44bda07 commit e5d9fae

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

‎git-commit-push-script.sh‎

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,30 @@ diff=$(git diff origin/$default_branch)
4242
# fi
4343

4444
# Stringify the diff
45-
diff=$(echo $diff | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\n/\\n/g')
45+
# diff=$(echo $diff | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\n/\\n/g')
46+
47+
# Default model (change if desired)
48+
MODEL="gemma3:4b"
49+
50+
# Prepare the prompt
51+
PROMPT=$(printf "You are an expert software engineer and technical writer. Write a clear, professional commit message based on the following Git diff. Requirements:\n- Summarize the purpose and key changes made, like if a file was created, edited, moved or deleted.\n- Include which files were created, modified, deleted (removed), or moved if applicable.\n- Do NOT include quotes, explanations, diff syntax, markdown formatting, or any additional text or formatting.\n- Limit your response to 20 tokens.\n\n Respond in the following format:\nCommit message: <Your concise commit message>\n\nGit diff:\n%s" "$diff")
52+
53+
# Run the model and capture output
54+
commit_message=$(echo "$PROMPT" | ollama run "$MODEL")
4655

4756
# Prepare the Gemini API request
48-
gemini_request='{"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 repsonse."}]}]}'
57+
#gemini_request='{"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 repsonse."}]}]}'
4958

50-
# Get commit message from Gemini API
51-
commit_message=$(curl -s \
52-
-H 'Content-Type: application/json' \
53-
-d "$gemini_request" \
54-
-X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
55-
| jq -r '.candidates[0].content.parts[0].text'
56-
)
59+
# # Get commit message from Gemini API
60+
#commit_message=$(curl -s \
61+
# -H 'Content-Type: application/json' \
62+
# -d "$gemini_request" \
63+
# -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
64+
# | jq -r '.candidates[0].content.parts[0].text'
65+
# )
5766

58-
# Clean up commit message formatting - remove #, ```, "", '', ()), and period . at the end of response
59-
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' | sed 's/\"//g' | sed "s/'//g" | sed 's/())//g' | sed 's/()//g' | sed 's/Commit message://g' | sed 's/Commit message title: //g' | sed 's/Commit message summary: //g' | sed 's/Commit message body: //g' | sed 's/Commit message body://g')
67+
# # Clean up commit message formatting - remove #, ```, "", '', ()), and period . at the end of response
68+
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' | sed 's/\"//g' | sed "s/'//g" | sed 's/())//g' | sed 's/()//g' | sed 's/Commit message://g' | sed 's/Commit message title: //g' | sed 's/Commit message summary: //g' | sed 's/Commit message body: //g' | sed 's/Commit message body://g'| sed 's/^\s*//;s/\s*$//'| sed 's/Code Review Request://g'| sed 's/Code Review://g'| sed 's/Summary of changes://g')
6069

6170
echo $commit_message
6271

@@ -74,9 +83,16 @@ fi
7483
# fi
7584

7685
# Echo the commit message
77-
echo $commit_message
86+
#echo $commit_message
7887

79-
$commit_message == null ? commit_message="Updated ${base_branch} branch" : echo "Commit message: $commit_message"
88+
# $commit_message == null ? commit_message="Updated ${base_branch} branch" : echo "Commit message: $commit_message"
89+
# Check for null commit message and set a default if necessary
90+
if [ "$commit_message" == "null" ] || [ -z "$commit_message" ]; then
91+
commit_message="Updated ${base_branch} branch"
92+
echo "Commit message is null or empty. Using default: $commit_message"
93+
else
94+
echo "Commit message: $commit_message"
95+
fi
8096

8197
# Set the GIT_SSH_PASSPHRASE environment variables
8298
export COMMIT_MESSAGE="$commit_message"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /