Created
November 10, 2023 00:17
-
-
Save richinseattle/e04728522c523986983e11c23f9cca70 to your computer and use it in GitHub Desktop.
bash OpenAI GPT client loop
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 | |
# bashGPT - rjohnson@fuzzing.io | |
[ "${OPENAI_API_KEY}" == "" ] && echo "Please set OPENAI_API_KEY env variable" && exit | |
[ "$(which jq)" == "" ] && echo "Please install the jq program" && exit | |
[ "$(which curl)" == "" ] && echo "Please install the curl program" && exit | |
PROMPT="$1" | |
while true | |
do | |
echo -n ">>>> " | |
[ "$PROMPT" != "" ] && echo $PROMPT | |
[ "$PROMPT" == "" ] && read PROMPT | |
REPLY="$(curl -s https://api.openai.com/v1/chat/completions \ | |
-H 'Content-Type: application/json' \ | |
-H "Authorization: Bearer $OPENAI_API_KEY" \ | |
-d '{ | |
"model": "gpt-3.5-turbo", | |
"messages": [{"role": "user", "content": "'"${PROMPT}"'"}] | |
}' | jq '.choices[0].message.content')" | |
PROMPT="" | |
echo -e ${REPLY:3:-1} | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment