Make chat shell script work by piping the content out of the subshell.
This commit is contained in:
parent
fc78910bc3
commit
6d72f0f070
1 changed files with 8 additions and 7 deletions
|
@ -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}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue