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=''
|
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}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue