Skip to content

Instantly share code, notes, and snippets.

@doitian
Last active March 7, 2023 13:21
Show Gist options
  • Select an option

  • Save doitian/4f3946239b622a0a669221b54ade5ba5 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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