Skip to content

Instantly share code, notes, and snippets.

Last active December 8, 2022 12:12
What would you like to do?
Use OpenAI's GPT3 model to generate pull request descriptions.
#!/usr/bin/env bash
# Print a summary of the current pull request's commits.
# Requires an OPENAI_API_KEY env var to authenticate requests - see:
# Commit selection variables.
# OpenAI tuning variables (can be overridden by passing as env vars).
INTRO=${INTRO:-"Write a summary of the commits in this pull request"}
# This command uses:
# - JQ to build the JSON payload (to handle escaping)
# - httpie to post it to the OpenAI REST API to generate the completion
# - JQ (again) to extract the completion text out of the response
# - sed to strip blank lines
jq -n \
--arg model "$MODEL" \
--argjson temp $TEMPERATURE \
--argjson tokens $MAX_TOKENS \
--arg prompt "$(
echo "$INTRO";
git log origin/$TARGET_BRANCH.. --format='%B';
)" '{model: $model, temperature: $temp, max_tokens: $tokens, prompt: $prompt}' \
| http Authorization:"Bearer $OPENAI_API_KEY" \
| jq -r '.choices[0].text' | sed '/./,$!d'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment