Created
March 6, 2023 23:14
-
-
Save martingaido/6903257409aacf265695cf6a2cb68d08 to your computer and use it in GitHub Desktop.
TerminalGPT
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 | |
# Replace YOUR_API_KEY with your actual API key | |
API_KEY="OPEN_AI_API_KEY" | |
# Get the message from the command line argument | |
MESSAGE=$1 | |
# Set up the API endpoint | |
API_ENDPOINT="https://api.openai.com/v1/chat/completions" | |
# Set up the JSON request body | |
JSON="{\"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"$MESSAGE\"}]}" | |
# Send the request to the API using curl | |
RESPONSE=$(curl -s -X POST \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $API_KEY" \ | |
-d "$JSON" \ | |
$API_ENDPOINT) | |
# Extract the response text from the JSON response | |
RESPONSE_TEXT=$(echo $RESPONSE | jq -r '.choices[].message.content') | |
# Print the response text to the console | |
echo "$RESPONSE_TEXT" | fold -w 100 -s | |
echo "" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment