Skip to content

Warn the user if OPENAI_API_KEY is not set #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion gpt3
Original file line number Diff line number Diff line change
@@ -41,6 +41,16 @@ set -- "${POSITIONAL[@]}" # restore positional parameter
[ -z "$2" ] && MAX_TOKENS=64 || MAX_TOKENS="$2"
[ -z "$OPENAI_KEY" ] && KEY="$OPENAI_API_KEY" || KEY="$OPENAI_KEY"

if [ -z "$KEY" ]; then
echo "You must set OPENAI_API_KEY or OPENAI_KEY"
exit 1
fi

line_buffered="-l"
if sed --version | grep GNU >/dev/null; then
line_buffered="-u"
fi

# FIXME: Improve error handling
curl -sSL -N \
-H "gpt3-cli/0.1.1 (https://github.com/CrazyPython/gpt3-cli)" \
@@ -50,6 +60,6 @@ curl -sSL -N \
--data-urlencode max_tokens="$MAX_TOKENS" \
--data-urlencode frequency_penalty="$FREQ_PENALTY" \
--data-urlencode presence_penalty="$PRES_PENALTY" \
-H "Authorization: Bearer $KEY" | sed -l 's/^data: //' | grep --line-buffer -v '^\[DONE\]$' | jq -j --unbuffered '.choices[0].text'
-H "Authorization: Bearer $KEY" | sed $line_buffered 's/^data: //' | grep --line-buffer -v '^\[DONE\]$' | jq -j --unbuffered '.choices[0].text'
# Add trailing newline
echo