Skip to content

Instantly share code, notes, and snippets.

@notpushkin
Created December 3, 2022 20:58
Show Gist options
  • Save notpushkin/6bfe47e4aa728406663190d000175b84 to your computer and use it in GitHub Desktop.
Save notpushkin/6bfe47e4aa728406663190d000175b84 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 2022 Alexander Pushkov, licensed ISC
# Usage: gptman curl in humorous style
set -e
OPENAI_API_KEY='...'
mandir="$(mktemp -d gptman.XXXXXX)"
trap "rm -rf ${mandir}" EXIT HUP INT QUIT TERM
man="${mandir}/page"
curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "text-davinci-003",
"prompt": "Write a manpage for '"$*"'. Output in troff format.\n",
"temperature": 0.7,
"max_tokens": 256,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
}' | jq -r '.choices[0].text' > "${man}"
man "${man}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment