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