15 lines
436 B
Bash
15 lines
436 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
# This script parses the event stream returned by prompt queries.
|
||
|
# It prints individual lines per ChatGPT response update.
|
||
|
|
||
|
while read -r line
|
||
|
do
|
||
|
[ -z "$line" ] && continue
|
||
|
[ "$line" == "data: [DONE]" ] && continue
|
||
|
event=$(echo "$line" | sed -e 's/^data: //')
|
||
|
content=$(echo "$event" | jq -e '.message.content.parts[0]')
|
||
|
[ ! $? -eq 0 ] && continue
|
||
|
echo "$content"
|
||
|
done < "${1:-/dev/stdin}"
|