Skip to content

Instantly share code, notes, and snippets.

@wandy-dev
Last active January 4, 2023 19:58
Show Gist options
  • Save wandy-dev/b8c95039c8a1894ca88ecaa1453bfe1e to your computer and use it in GitHub Desktop.
Save wandy-dev/b8c95039c8a1894ca88ecaa1453bfe1e to your computer and use it in GitHub Desktop.
GPT chat bot for the terminal.
#!/bin/bash
api_call() {
curl --no-progress-meter https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d "{
\"model\": \"text-davinci-003\",
\"prompt\": \"$@\",
\"temperature\": 0,
\"max_tokens\": 1024
}" | jq ".choices" | jq '.[0].text' | sed 's/\"//g' | sed 's/\\n//g'
}
while true; do
read -p "You: "
response=$(api_call "$REPLY")
echo "GPT: $response"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment