aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-03-24 10:15:23 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-03-24 10:19:10 +0800
commite65d2df31888271808293290a158f74e8246e7f5 (patch)
tree00d9edf84984d711e92ec06df4b72aa529f0394f
parent2ddb86eab39298a11d6fed7c29a4752a80430898 (diff)
Update
-rwxr-xr-xbin/gpt/gpt10
1 files 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 )
15# If script is interupt by SIGINT, simply print leave message 15# If script is interupt by SIGINT, simply print leave message
16trap _print_leave_message INT 16trap _print_leave_message INT
17 17
18# If any stack is missing, exit with 2
18_check_stacks() { 19_check_stacks() {
19 for command in "${stacks[@]}"; do 20 for command in "${stacks[@]}"; do
20 which "$command" &>/dev/null && continue 21 which "$command" &>/dev/null && continue
21 echo "$command" is needed 22 echo "$command" is needed
22 exit 1 23 exit 2
23 done 24 done
24} 25}
25 26
@@ -71,7 +72,7 @@ EOF
71 72
72_print_leave_message(){ 73_print_leave_message(){
73 tokens=$(jq '.usage? // empty | .total_tokens' "$cache" | paste -sd+ | bc) 74 tokens=$(jq '.usage? // empty | .total_tokens' "$cache" | paste -sd+ | bc)
74 echo -e "\nChat Finished, ${tokens:-0} tokens used. Session is cached in: $cache" 75 echo -e "\nChat ends, ${tokens:-0} tokens used. Session is cached in: $cache"
75 exit 0 76 exit 0
76} 77}
77 78
@@ -132,9 +133,10 @@ _get_content() {
132 fi 133 fi
133} 134}
134 135
135# Check OPENAI API KEY"Department:" 3 1 "" 3 15 25 0 136# Check OPENAI API KEY in env
137# Exit with 6 (configuration issue) if it is not set
136[ -z "$OPENAI_API_KEY" ] && which token &>/dev/null && OPENAI_API_KEY=$(token openai) 138[ -z "$OPENAI_API_KEY" ] && which token &>/dev/null && OPENAI_API_KEY=$(token openai)
137[ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 1; } 139[ -z "$OPENAI_API_KEY" ] && { echo API KEY not specified; exit 6; }
138 140
139# Parse arguments 141# Parse arguments
140while [ "$#" -gt 0 ]; do 142while [ "$#" -gt 0 ]; do