-
-
Save todgru/f14b6021826c660b2db1765b0018987a to your computer and use it in GitHub Desktop.
Small bash script to use ChatGPT from 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 | |
if test -z "$1"; then | |
echo "Usage: $0 <prompt>" | |
exit 1 | |
fi | |
if test -z "$OPENAI_API_KEY"; then | |
echo "OpenAI key is missing - \$OPENAI_API_KEY must be set" | |
exit 1 | |
fi | |
prompt="$*" | |
curl https://api.openai.com/v1/chat/completions -s \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPENAI_API_KEY" \ | |
-d "{\"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"$prompt\"}], \"temperature\": 0.7 }" \ | |
| jq -r '.choices[0].message.content' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment