In ~/.profile
:
alias ask="$HOME/.quickgpt"
alias syn="ask 20 synonyms and their nuances of:"
alias def="ask definition and usage example of:"
alias term="ask 5 most accurate terms and their nuances that describe:"
In ~/.profile
:
alias ask="$HOME/.quickgpt"
alias syn="ask 20 synonyms and their nuances of:"
alias def="ask definition and usage example of:"
alias term="ask 5 most accurate terms and their nuances that describe:"
#!/bin/bash | |
# Title: QuickGPT | |
# Version: 0.1 | |
# Date: 2024-05-21 | |
# License: MIT | |
# Author: dctremblay@dasio.ca | |
[ $OPENAI_API_KEY ] || { echo "OPENAI_API_KEY env var must be set" >&2; exit 1; } | |
gptModel="gpt-4o" #gpt-3.5-turbo | |
role="you answer the most concise and short way possible" | |
query() { | |
curl -s https://api.openai.com/v1/chat/completions \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPENAI_API_KEY" \ | |
-d "$(cat <<-EOF | |
{ | |
"model": "$gptModel", | |
"messages": $1 | |
} | |
EOF | |
)" | |
} | |
function esc() { sed 's/"/\\"/g' <<< "$1"; } | |
prompt="$@" | |
conv="[{\"role\":\"system\", \"content\": \"$(esc "$role")\"},{\"role\":\"user\", \"content\": \"$(esc "$prompt")\"}]" | |
jsonAnswer=$(query "${conv}" | jq .choices[0].message) | |
jq -j .content <<< "$jsonAnswer" | |
echo |