Created
March 2, 2023 11:45
-
-
Save apostoloss/87b0ebbbffb372c8360a7559c5f5b467 to your computer and use it in GitHub Desktop.
chatgpt query from cli
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
#!/usr/bin/env bash | |
# openai api token | |
# use gopass to keep this or just replace it below (nah) | |
BEARER="$(gopass show openai_api)" | |
# api configuration | |
MODEL="text-davinci-003" | |
TEMPERATURE="0" | |
MAX_TOKEN=4000 | |
function chatgpt() { | |
# use with: chatgpt this is my query | |
# as is it does not work with quotes, question marks and any other character that shell interprets as non text | |
MYQUERY=$@ | |
_body="{ | |
\"model\": \"$MODEL\", | |
\"prompt\": \"$MYQUERY\", | |
\"max_tokens\": $MAX_TOKEN, | |
\"temperature\": $TEMPERATURE | |
}" | |
local _response=$(curl https://api.openai.com/v1/completions \ | |
-H 'Content-Type: application/json' \ | |
-H "Authorization: Bearer $BEARER" \ | |
-d ${_body} \ | |
2>/dev/null | jq '.choices[]'.text | cut -c 6-) | |
echo """${_response}""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment