Skip to content

Instantly share code, notes, and snippets.

@chrisblatchley
Created December 22, 2022 06:45
Show Gist options
  • Save chrisblatchley/049079cd2c4d1819362d03396cccc21f to your computer and use it in GitHub Desktop.
Save chrisblatchley/049079cd2c4d1819362d03396cccc21f to your computer and use it in GitHub Desktop.
FDI: Fucking do it. use openAI codex to help jog your memory for those less used commands
#!/usr/local/bin/bb
(require '[babashka.curl :as curl])
(require '[babashka.process :refer [sh]])
; assume your api-key is stored in ~/openai.edn
(def openai-cfg (clojure.edn/read-string (slurp (str (System/getProperty "user.home") "/.openai.edn"))))
(defn pre-prompt
[prompt]
(str "# # shell command to list files in home directory\n"
"ls ~\n"
"# shell command to" prompt))
(defn completions
[prompt]
(-> "https://api.openai.com/v1/completions"
(curl/post {:headers {"Authorization" (str "Bearer " (:api-key openai-cfg))
"Content-type" "application/json"}
:body (json/encode {:model "code-cushman-001"
:temperature 0.0
:max_tokens 20
:prompt (pre-prompt prompt)})})
:body
(json/parse-string)
(get-in ["choices" 0 "text"])
(clojure.string/split-lines)
(get 1)))
(let [suggestion (completions (apply str *command-line-args*))
cmd (clojure.string/split suggestion #" ")]
(println (str "`" suggestion "`") "ok? [y/n]")
(if (= "y" (read-line))
(println (:out (sh suggestion)))
(println "aborted!")))
; usage:
; `$ fucking get my ip address`
; `curl ifconfig.me` ok? [y/n]
; y
; 192.168.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment