2023-10-10 21:44:37 +03:00
|
|
|
|
#!/usr/bin/env -S tea bash
|
2023-10-10 21:47:05 +03:00
|
|
|
|
# shellcheck shell=bash
|
2023-10-10 21:44:37 +03:00
|
|
|
|
|
|
|
|
|
#---
|
|
|
|
|
# dependencies:
|
|
|
|
|
# charm.sh/gum: '*'
|
|
|
|
|
#---
|
2023-06-20 18:48:16 +03:00
|
|
|
|
|
|
|
|
|
set -eo pipefail
|
|
|
|
|
|
2023-07-30 15:00:35 +03:00
|
|
|
|
# attempt to get the key from the user’s shell rc files (if set)
|
2023-10-10 21:47:05 +03:00
|
|
|
|
if [ -z "$OPENAI_API_KEY" ] && [ -n "$SHELL" ]; then
|
|
|
|
|
# shellcheck disable=SC2155,2016
|
2023-07-30 15:00:35 +03:00
|
|
|
|
export OPENAI_API_KEY="$(env -i "$SHELL" -ic 'echo $OPENAI_API_KEY')"
|
|
|
|
|
fi
|
|
|
|
|
|
2023-10-10 21:47:05 +03:00
|
|
|
|
if [ -z "$OPENAI_API_KEY" ]; then
|
2023-06-20 18:48:16 +03:00
|
|
|
|
gum format <<EoMD
|
|
|
|
|
# OpenAI API key required
|
|
|
|
|
You need an OpenAI API key to use this package.
|
|
|
|
|
|
|
|
|
|
> https://platform.openai.com/account/api-keys
|
|
|
|
|
|
2023-07-21 16:57:49 +03:00
|
|
|
|
GPT4 is recommended (but you gotta sign up for the
|
|
|
|
|
the [waitlist](https://openai.com/waitlist/gpt-4-api))
|
2023-06-20 18:48:16 +03:00
|
|
|
|
|
2023-10-10 21:47:05 +03:00
|
|
|
|
**this key will not be persisted by pkgx!**
|
2023-06-20 18:48:16 +03:00
|
|
|
|
EoMD
|
2023-07-21 16:57:49 +03:00
|
|
|
|
|
|
|
|
|
echo # spacer
|
|
|
|
|
|
2023-10-10 21:47:05 +03:00
|
|
|
|
# shellcheck disable=SC2155
|
2023-07-27 16:58:38 +03:00
|
|
|
|
export OPENAI_API_KEY="$(gum input --placeholder 'key pls')"
|
2023-06-20 18:48:16 +03:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
gum format <<EoMD
|
|
|
|
|
# what do you want to build?
|
|
|
|
|
|
|
|
|
|
the example prompt \`gpt-engineer\` provide is:
|
|
|
|
|
|
|
|
|
|
> we are writing snake in python. MVC components split in separate files. keyboard control.
|
|
|
|
|
|
|
|
|
|
type your prompt below (⌃D when done)
|
|
|
|
|
EoMD
|
|
|
|
|
|
|
|
|
|
echo #spacer
|
|
|
|
|
|
|
|
|
|
prompt="$(gum write --placeholder 'main prompt…')"
|
|
|
|
|
|
|
|
|
|
gum format <<EoMD
|
|
|
|
|
# we store the results in your documents folder, what’s the title?
|
|
|
|
|
EoMD
|
|
|
|
|
|
|
|
|
|
title="$(gum input --placeholder 'title?')"
|
|
|
|
|
|
|
|
|
|
docs="${XDG_DOCUMENTS_DIR:-$HOME/Documents}/GPT Engineer"
|
|
|
|
|
|
|
|
|
|
mkdir -p "$docs/$title"
|
|
|
|
|
echo "$prompt" > "$docs/$title/main_prompt"
|
|
|
|
|
|
|
|
|
|
gum format <<EoMD
|
|
|
|
|
> output will be written to \`$docs/$title\`
|
|
|
|
|
|
|
|
|
|
# running \`gpt-engineer\`
|
|
|
|
|
EoMD
|
|
|
|
|
|
|
|
|
|
exec gpt-engineer "$docs/$title"
|