diff options
-rw-r--r-- | krebs/2configs/reaktor2.nix | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index 502dd4a9f..0a5031415 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -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)"' |