Last active
March 21, 2023 13:40
-
-
Save mhyee/06e250cdc30a560cdaaea09078cfd6f3 to your computer and use it in GitHub Desktop.
"Compile" code with the OpenAI Codex model
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
#!/bin/bash | |
# Super simple "compiler" that uses OpenAI's Codex model. | |
# The Codex API was free before being discontinued on March 23, 2023. | |
# | |
# Usage: | |
# ./codex_compiler.sh input_file > out | |
# | |
# Requirements: | |
# - OpenAI API key (set the environment variable OPENAI_API_KEY) | |
# - jq (https://stedolan.github.io/jq/) | |
file=$(cat $1 | awk -v ORS='\\n' 1 | sed 's/"/\\"/g') | |
prompt="Turn this into x86 assembly:\n$file\nmain:" | |
echo -n "main:" | |
curl https://api.openai.com/v1/completions \ | |
--silent \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPENAI_API_KEY" \ | |
-d \ | |
"{ | |
\"model\": \"code-davinci-002\", | |
\"prompt\": \"$prompt\", | |
\"max_tokens\": 256, | |
\"temperature\": 0.2, | |
\"top_p\": 0.95, | |
\"n\": 1, | |
\"stop\": [\";\", \"/*\", \"\\\\#\"] | |
}" | jq -r '.choices[0].text' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment