Created
March 3, 2023 13:25
-
-
Save mauvehed/bac410138028f83a9851fb15e5a3c7a7 to your computer and use it in GitHub Desktop.
ChatGPT lookup using bash on the command line
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 - richinseattle (who failed to gist it, but all credit is given) | |
[ "${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