From e65d2df31888271808293290a158f74e8246e7f5 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Fri, 24 Mar 2023 10:15:23 +0800 Subject: Update --- bin/gpt/gpt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/gpt/gpt b/bin/gpt/gpt index 51de0a8..6d34075 100755 --- a/bin/gpt/gpt +++ b/bin/gpt/gpt @@ -15,11 +15,12 @@ configurable_options=( behavior temperature max_tokens ) # If script is interupt by SIGINT, simply print leave message trap _print_leave_message INT +# If any stack is missing, exit with 2 _check_stacks() { for command in "${stacks[@]}"; do which "$command" &>/dev/null && continue echo "$command" is needed - exit 1 + exit 2 done } @@ -71,7 +72,7 @@ EOF _print_leave_message(){ tokens=$(jq '.usage? // empty | .total_tokens' "$cache" | paste -sd+ | bc) - echo -e "\nChat Finished, ${tokens:-0} tokens used. Session is cached in: $cache" + echo -e "\nChat ends, ${tokens:-0} tokens used. Session is cached in: $cache" exit 0 } @@ -132,9 +133,10 @@ _get_content() { fi } -# Check OPENAI API KEY"Department:" 3 1 "" 3 15 25 0 +# Check OPENAI API KEY in env +# Exit with 6 (configuration issue) if it is not set [ -z "$OPENAI_API_KEY" ] && which token &>/dev/null && OPENAI_API_KEY=$(token openai) -[ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 1; } +[ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 6; } # Parse arguments while [ "$#" -gt 0 ]; do -- cgit v1.2.3-70-g09d2