Created
May 28, 2023 06:29
-
-
Save finesse-fingers/8ffa35f5d2ac1b4ee9ac2c136e2448ed to your computer and use it in GitHub Desktop.
Ask GPT zsh alias
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
ask_gpt() { | |
# print the prompt in blue | |
echo -e "\e[34mPrompt: \"$1\"\e[0m" | |
# make a a slient request and store the result | |
response=$(curl https://api.openai.com/v1/completions \ | |
--silent \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer {TOKEN}" \ | |
-d '{ | |
"model": "text-davinci-003", | |
"prompt": "'$1'", | |
"temperature": 0, | |
"max_tokens": 512, | |
"top_p": 1, | |
"frequency_penalty": 0, | |
"presence_penalty": 0 | |
}' | jq -r '.choices[].text') | |
# print the response in magenta | |
echo -e "\e[35m$response\e[0m" | |
} | |
alias ask="ask_gpt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment