Skip to content

Instantly share code, notes, and snippets.

@stuhlmueller
Last active May 23, 2022 09:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stuhlmueller/099b545e1718d7086cb180873601b7b9 to your computer and use it in GitHub Desktop.
Save stuhlmueller/099b545e1718d7086cb180873601b7b9 to your computer and use it in GitHub Desktop.
OpenAI Codex in Emacs
(defun codex (&optional b e)
(interactive "r")
(shell-command-on-region b e "codex.py" nil nil))
#!/usr/bin/env python
# Make this file executable (chmod +x codex.py)
# and put it somewhere in your PATH
import sys
import openai
openai.api_key = "sk-[YOUR API KEY HERE]"
prompt = "".join(sys.stdin.readlines())
completion = openai.Completion.create(
engine="davinci-codex",
prompt=prompt,
max_tokens=100,
temperature=0,
frequency_penalty=0.2
)
print(completion.choices[0].text)
@bitcoinmeetups
Copy link

How does it work? Will codex give working code completions? Can you also ask it questions in human languages and it will answer with code using your script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment