Skip to content

Ensure GNU sed works like BSD sed #11

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 1 commit 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
7 changes: 6 additions & 1 deletion gpt3
Original file line number Diff line number Diff line change
@@ -41,6 +41,11 @@ set -- "${POSITIONAL[@]}" # restore positional parameter
[ -z "$2" ] && MAX_TOKENS=64 || MAX_TOKENS="$2"
[ -z "$OPENAI_KEY" ] && KEY="$OPENAI_API_KEY" || KEY="$OPENAI_KEY"

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 +55,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