From 6d72f0f070e2a7f8e98e040aac5f5325c3616df6 Mon Sep 17 00:00:00 2001 From: Randall Fitzgerald Date: Mon, 12 Jun 2023 19:44:53 -0400 Subject: [PATCH] Make chat shell script work by piping the content out of the subshell. --- examples/server/chat.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/server/chat.sh b/examples/server/chat.sh index 2429da665..ddd4418bd 100644 --- a/examples/server/chat.sh +++ b/examples/server/chat.sh @@ -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}"