Created
April 1, 2023 12:06
-
-
Save qapquiz/c7c80a4f267c1d04247c398d466285a6 to your computer and use it in GitHub Desktop.
ask.sh (ask ChatGPT in 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 | |
function ask_gpt() { | |
PROMPT=$(gum input --width 80 --placeholder "prompt") | |
if [[ -z "$PROMPT" ]]; then | |
exit 0 | |
fi | |
gum style --foreground 212 "> $PROMPT" | |
RESULT=$(gum spin -s line --title "Asking ChatGPT..." --show-output -- curl -sS https://api.openai.com/v1/chat/completions \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPEN_API_KEY" \ | |
-d '{ | |
"model": "gpt-3.5-turbo", | |
"messages": [{"role": "user", "content": "'"$PROMPT"'"}] | |
}' | jq ".choices[0].message.content" | |
) | |
printf "$RESULT" | glow | |
} | |
while true; do | |
ask_gpt | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo