reaktor2 bing: add error reporting

This commit is contained in:
lassulus 2023-04-17 16:43:31 +02:00
parent 4ca30a227b
commit ac5e8cc3f4

View File

@ -59,6 +59,13 @@ let
command = {
filename = pkgs.writeDash "bing" ''
set -efu
report_error() {
printf '%s' "$*" |
curl -Ss http://p.r --data-binary @- |
tail -1 |
echo "error $(cat)"
exit 0
}
export PATH=${makeBinPath [
pkgs.coreutils
pkgs.curl
@ -68,13 +75,13 @@ let
curl -SsG http://bing-gpt.r/api/chat --data-urlencode 'prompt@-'
)
if [ "$?" -ne 0 ]; then
printf '%s' "$response" |
curl -Ss http://p.r --data-binary @- |
tail -1
report_error "$response"
else
printf '%s' "$response" |
jq -r '.item.messages[1].text' |
echo "$_from: $(cat)"
if ! text=$(printf '%s' "$response" | jq -er '.item.messages[1].text'); then
echo "$_from: $(report_error "$response")"
exit 0
fi
printf '%s' "$text" | echo "$_from: $(cat)"
printf '%s' "$response" |
jq -r '[.item.messages[1].sourceAttributions[].seeMoreUrl] | to_entries[] | "[\(.key + 1)]: \(.value)"'