Last active
January 26, 2023 21:53
-
-
Save raaar/6b165e9798ce91665170e6b108e5b6b3 to your computer and use it in GitHub Desktop.
Ask a question from the terminal: sh ./chat.sh "what's the time?"
This file contains hidden or 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 | |
# Set the API key | |
source ~/env.sh | |
endpoint="https://api.openai.com/v1/completions" | |
max_tokens=${2:-50} | |
prompt=$1 | |
temperature=0.5 | |
model="text-davinci-003" | |
response=$(curl https://api.openai.com/v1/completions \ | |
-H "Content-Type: application/json" \ | |
-H "charset=UTF-8" \ | |
-H "Authorization: Bearer $api_key" \ | |
-d "{\"model\": \"$model\", \"prompt\": \"$prompt\", \"temperature\": $temperature, \"max_tokens\": $max_tokens}") | |
printf '%s' "$response" | jq -r '.choices[0].text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment