Last active
June 20, 2024 02:40
-
-
Save konsalex/bf6a2365416e34a8745cc31af9a2611f to your computer and use it in GitHub Desktop.
Generate a commit message based on a changeset file π¦ using ollama π¦
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
file=$(find ./.changeset/ -type f -name '*.md' | grep -E '^[./a-z-]+\.md$') | |
prompt_template=$(cat <<-END | |
You are a programmer, trained to write commit messages. | |
You follow the Conventional Commits specification. | |
feat: for new features | |
chore: for maintenance work | |
fix: for bug fixes | |
Below, you will receive a changeset, which is a list of changes to the codebase. | |
Based on this information generate a commit message. | |
Example changeset: | |
''' | |
--- | |
"@neo4j-ndl/base": minor | |
--- | |
added a boolean variable to the button to control disabled states and modify styles | |
''' | |
Example commit message: 'feat: added new disabled boolean variable to button' | |
Return the commit message as a json response. | |
THE RESULT SHOULD ONLY BE A VALID JSON! | |
Example response: | |
{ | |
"commit": "feat: added new disabled boolean variable to button" | |
} | |
Keep the generated commit message strictly under 50 characters, if its more summarise it. | |
THE COMMIT MESSAGE SHOULD NOT BE MORE THAN 50 CHARACTERS!!!!! | |
Do not mention the name of the package (in the example @neo4j-ndl/base), | |
and do not include any other information/text rather than the commit message itself. | |
Changeset:\n | |
END | |
) | |
prompt_template+="$(cat $file)" | |
# Write response to test.json for testing | |
#http POST http://localhost:11434/api/generate model=codellama prompt="$prompt_template" stream:=false | jq .response > test.json | |
commit_message=$(http POST http://localhost:11434/api/generate options:='{"seed": 42, "temperature": 0.9}' model=llama2:13b-chat prompt="$prompt_template" stream:=false | jq .response) | |
# Parsefro JSON response | |
commit_clean=$(jq "fromjson | .commit" <<< $commit_message) | |
echo "π€ Your commit message:" | |
echo "$commit_clean" | |
printf "\n\nπ Commit message copied to clipboard" | |
echo "$commit_clean" | pbcopy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment