Make chat shell script work by piping the content out of the subshell.

This commit is contained in:
Randall Fitzgerald 2023-06-12 19:44:53 -04:00
parent fc78910bc3
commit 6d72f0f070

View file

@ -41,24 +41,25 @@ chat_completion() {
ANSWER=''
curl \
--silent \
--no-buffer \
--request POST \
--url "${API_URL}/completion" \
--data-raw "${DATA}" | while IFS= read -r LINE; do
while IFS= read -r LINE; do
if [[ $LINE = data:* ]]; then
CONTENT="$(echo "${LINE:5}" | jq -r '.content')"
printf "%s" "${CONTENT}"
ANSWER+="${CONTENT}"
fi
done
done < <(curl \
--silent \
--no-buffer \
--request POST \
--url "${API_URL}/completion" \
--data-raw "${DATA}")
printf "\n"
CHAT+=("$1" "${ANSWER:1}")
}
while true; do
read -e -p "> " QUESTION
chat_completion "${QUESTION}"