Skip to content

Instantly share code, notes, and snippets.

@cataphract
Last active March 31, 2023 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cataphract/4a18bbafdd23d7575ff25735c7989b2f to your computer and use it in GitHub Desktop.
Save cataphract/4a18bbafdd23d7575ff25735c7989b2f to your computer and use it in GitHub Desktop.
function _h {
local postprompt=$1
local prompt
if [[ $# -eq 1 || $2 == '-' ]]; then
prompt=$(cat)
else
prompt="$2"
fi
prompt=$(echo "$prompt"$'\n'"$postprompt" | jq -sR '@text')
#echo "$prompt"
#return
curl https://api.openai.com/v1/chat/completions -s \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": '"$prompt"'}],
"temperature": 0.7
}' | \
jq -r '.choices[0].message.content'
}
function h {
_h '' "$@"
}
function hm {
_h 'Use markdown to format the output' "$@" | glow
}
function hc {
_h 'Display only the code (no explanations), without any extraneous materials' "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment