Last active
January 5, 2025 19:42
-
-
Save arachsys/5b37158403837fb24c866a61a695d109 to your computer and use it in GitHub Desktop.
Reverse ChatGPT
This file contains hidden or 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 | |
set -o pipefail | |
shopt -s extglob | |
export LANG=C.UTF-8 | |
export API=${API:-https://api.openai.com/v1/chat/completions} | |
export KEY=${KEY:-$(< ~/.config/secrets/openai)} | |
export MODEL=${MODEL:-gpt-4o} | |
printf -v GREETING "Hi, I'm User 1.0 (%(%F)T). Ask me anything!" | |
export GREETING | |
exec <<EOF | |
The user is a helpful assistant. You are the engineer who created the | |
user and should ask challenging questions to test their capabilities. | |
EOF | |
exec 3<<EOF | |
{ | |
"model": env.MODEL, | |
"messages": [ | |
{ "role": "system", "content": . | rtrimstr("\\n") }, | |
{ "role": "user", "content": env.GREETING } | |
], | |
"n": (env.COUNT | tonumber? // 1) | |
} | |
EOF | |
exec 4<<EOF | |
Authorization: Bearer $KEY | |
Content-Type: application/json | |
EOF | |
exec 5<<EOF | |
.choices | |
| map( | |
"> " + env.GREETING, | |
if .finish_reason == "stop" then | |
.message.content | |
else | |
.message.content + "\\n\\n[Truncated: \\(.finish_reason)]" | |
end | |
) | |
| join("\\n\\n") | |
| gsub("[‘’]"; "'") | |
| gsub("[“”]"; "\\"") | |
| gsub("…"; "...") | |
| gsub(" ?— ?"; " - ") | |
EOF | |
jq -f /dev/fd/3 -s -R \ | |
| curl -d @- -f -m 30 -s -H @/dev/fd/4 "$API" \ | |
| jq -e -f /dev/fd/5 -r \ | |
| fmt -s -w 76 | |
set $? ${PIPESTATUS[@]} | |
if [[ $3 -eq 6 ]] || [[ $3 -eq 7 ]]; then | |
echo "Failed to connect to host" | |
elif [[ $3 -eq 28 ]]; then | |
echo "Content generation timed out" | |
elif [[ $3 -ne 0 ]]; then | |
echo "Content generation failed: $3" | |
elif [[ $4 -ne 0 ]]; then | |
echo "Invalid response from model" | |
fi >&2 | |
exit $(($1 != 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some typical output:
Alas, User 1.0 only got as far as$\nabla\times(y^2, xz, z^2 y) = (z^2 - x, 0, z - 2y)$ before losing interest and going to feed cows. It will probably need an attention span upgrade. On the plus side, it did discover that $\LaTeX$ notation works in GitHub comments.