Last active
March 7, 2023 13:21
-
-
Save doitian/4f3946239b622a0a669221b54ade5ba5 to your computer and use it in GitHub Desktop.
Git commit with OpenAI generated message based on https://goonlinetools.com/snapshot/code/#42rshrrrk3gq5h171lxiu
This file contains hidden or 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 | |
| if [ -z "${OPENAI_API_KEY:-}" ]; then | |
| export OPENAI_API_KEY="$(gopass show key/openai.com/personal)" | |
| fi | |
| system_message="You are a helpful assistant who writes short git commit messages." | |
| user_message="Write the commit message for the following changes: | |
| $(git diff --cached)" | |
| message="$(openai api chat_completions.create -m gpt-3.5-turbo -g system "$system_message" -g user "$user_message")" | |
| message="$(tr '[:upper:]' '[:lower:]' <<< ${message:0:1})$(sed -e '1s/[.!?]$//' <<< ${message:1})" | |
| git commit -m "$message" -e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment