Title: Improve reset functionality

Content: Add error handling for resetting conversation.
This commit is contained in:
ilguappo 2024-08-07 03:23:49 -07:00
parent 3149d1e73b
commit 9efdd307ab

View File

@ -4,7 +4,7 @@ set -o pipefail
ARGS=("${@-}")
pushd "$(pwd)" "$@" >/dev/null
pushd "$(pwd)" >/dev/null
TMP_FILE="/tmp/aicommit"
@ -35,9 +35,11 @@ message=$(
".message = $(jq -R -s '@json' <<<"${message_cat}")"
)
# trunk-ignore(shellcheck/SC2091)
# trunk-ignore(shellcheck/SC2310)
if $(hasFlag -r --reset); then
curl -s -X POST https://infer.x64.world/reset-conversation "$@" >/dev/null
if ! curl -s -X POST https://infer.x64.world/reset-conversation "$@" >/dev/null; then
echo "resetting AI history."
if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then
echo "Failed to reset conversation."
exit 1
fi
@ -48,6 +50,7 @@ curl -s "https://infer.x64.world/chat" \
-H "Content-Type: application/json" \
-d "${message}" | jq -r '.content | gsub("\""; "")' >"${TMP_FILE}"
# trunk-ignore(shellcheck/SC2181)
if [[ 0 -ne $? ]]; then
echo "Failed to get response."
exit 1
@ -55,4 +58,4 @@ fi
git commit -e -m "$(cat "${TMP_FILE}")" && rm "${TMP_FILE}"
popd "$@" >/dev/null
popd >/dev/null