Last active
March 31, 2023 10:42
-
-
Save cataphract/4a18bbafdd23d7575ff25735c7989b2f to your computer and use it in GitHub Desktop.
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
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