This gpt()
function reads input from the command line and then sends a formatted JSON object to the OpenAI API for the GPT-4 model. It properly escapes special characters and checks for the .env
file containing the OpenAI API key.
Usage:
- Load the function into your environment:
source gpt.sh
. - Make sure to have an
.env
file in the current directory with theOPENAI_API_KEY
. - Pipe anything itno it, and also add a prompt, example:
git diff main | gpt "As a programmer, review this diff. Provide feedback only if necessary. Be brief"