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