Last active
May 31, 2023 11:55
-
-
Save Briscoooe/a1a6a605c8b6dca9db7696c3b122a8bd to your computer and use it in GitHub Desktop.
Bash command for asking ChatGPT stuff directly from the command line. Add this to your ~/.zshrc, ~/.bashrc, etc. and away you go
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
gpt() { | |
local input=$1 | |
local model="gpt-3.5-turbo" | |
local temperature=0.5 | |
local url="https://api.openai.com/v1/chat/completions" | |
local payload="{\"model\":\"$model\",\"messages\":[{\"role\":\"system\",\"content\":\"You are ChatGPT, a large language model trained by OpenAI.\\nKnowledge cutoff: 2021-09\\nCurrent date and time: $(date +%d/%m/%Y,%H:%M:%S)\"},{\"role\":\"user\",\"content\":\"$input\"}],\"temperature\":$temperature,\"stream\":false}" | |
local gpt=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $OPEN_AI_KEY" -d "$payload" "$url") | |
echo "$gpt" | sed 's/$/\\n/' | tr -d '\n' | sed -e 's/“/"/g' -e 's/”/"/g' | sed '$ s/\\n$//' | jq -r '.choices[0].message.content' | glow - | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment