Skip to content
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
Expand Up @@ -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)" \
Expand All @@ -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