Skip to content

Instantly share code, notes, and snippets.

@finesse-fingers
Created May 28, 2023 06:29
Show Gist options
  • Save finesse-fingers/8ffa35f5d2ac1b4ee9ac2c136e2448ed to your computer and use it in GitHub Desktop.
Save finesse-fingers/8ffa35f5d2ac1b4ee9ac2c136e2448ed to your computer and use it in GitHub Desktop.
Ask GPT zsh alias
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