Skip to content

Instantly share code, notes, and snippets.

@mauvehed
Created March 3, 2023 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauvehed/bac410138028f83a9851fb15e5a3c7a7 to your computer and use it in GitHub Desktop.
Save mauvehed/bac410138028f83a9851fb15e5a3c7a7 to your computer and use it in GitHub Desktop.
ChatGPT lookup using bash on the command line
#!/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