Created
March 19, 2023 20:13
-
-
Save ccmiller2018/2aa4c2cc81d818b948ee9e41144b429b to your computer and use it in GitHub Desktop.
This gist gives you a great starting place to chat with ChatGPT 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 | |
# Check if input string is provided | |
if [ -z "$1" ] | |
then | |
echo "Please provide a string input"; | |
exit 1; | |
fi | |
# Tell the user i am thinking | |
echo "I'm thinking..." | |
# Send HTTP request to OpenAI API | |
response=$(curl -s "https://api.openai.com/v1/chat/completions" \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPEN_AI_API_KEY" \ | |
-d '{"model":"gpt-3.5-turbo","messages": [{"role":"user","content":"'"$1"'"}], "temperature": 0.7}') | |
# Check for errors | |
if [ -z "$response" ] | |
then | |
echo "Error: No response from OpenAI API"; | |
exit 1; | |
fi | |
# Parse response to get the best result | |
best_result=$(echo "$response" | jq -r '.choices[0].message.content'); | |
# Display the best result | |
echo $best_result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment