summaryrefslogtreecommitdiffstats
path: root/krebs/2configs
diff options
context:
space:
mode:
authorlassulus <git@lassul.us>2023-04-17 16:43:31 +0200
committerlassulus <git@lassul.us>2023-04-17 16:43:31 +0200
commitac5e8cc3f4905d4e0e3beedb2ea67e749fccb80a (patch)
tree13a26d91447f9825826839a08f402d436aaf7b49 /krebs/2configs
parent4ca30a227ba7728a0190b0d5ea0fa4d424142ee5 (diff)
reaktor2 bing: add error reporting
Diffstat (limited to 'krebs/2configs')
-rw-r--r--krebs/2configs/reaktor2.nix19
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)"'