aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-03-25 23:50:20 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-03-26 12:30:01 +0800
commitd68c4038b1dbfd745c6103f99346b65ee36a39b7 (patch)
treeddfde5041d57db40e81fac4a774a54903fd56b44
parent7902ab57bcb380d246496970490b77d4eda0efd2 (diff)
Update
-rwxr-xr-xbin/gpt/gpt13
1 files changed, 12 insertions, 1 deletions
diff --git a/bin/gpt/gpt b/bin/gpt/gpt
index 6468f22..9e6cff8 100755
--- a/bin/gpt/gpt
+++ b/bin/gpt/gpt
@@ -65,6 +65,8 @@ Options:
65 your latest prompt input. (By default, API calls use the 65 your latest prompt input. (By default, API calls use the
66 whole previous chats, which is not friendly to token usage) 66 whole previous chats, which is not friendly to token usage)
67 67
68 -v|--verbose If set, print token usage after each completion.
69
68 * The other arguments would be treated as message content. 70 * The other arguments would be treated as message content.
69 If no message is specified, user should input content by hands. 71 If no message is specified, user should input content by hands.
70 If STDIN is given, it would be append to the end of message. 72 If STDIN is given, it would be append to the end of message.
@@ -86,7 +88,7 @@ _print_leave_message(){
86 tokens=$(jq '.usage? // empty | .total_tokens' "$cache" | paste -sd+ | bc) 88 tokens=$(jq '.usage? // empty | .total_tokens' "$cache" | paste -sd+ | bc)
87 echo -en "${tokens:-0} tokens used. " 89 echo -en "${tokens:-0} tokens used. "
88 fi 90 fi
89 echo Session is cached in: "$cache" 91 echo Session is cached in "$cache"
90 exit 0 92 exit 0
91} 93}
92 94
@@ -218,6 +220,10 @@ while [ "$#" -gt 0 ]; do
218 context=$2 220 context=$2
219 shift 2 221 shift 2
220 ;; 222 ;;
223 -v|--verbose)
224 VERBOSE=true
225 shift 1
226 ;;
221 -h|--help) 227 -h|--help)
222 _print_helper_message 228 _print_helper_message
223 exit 0 229 exit 0
@@ -291,6 +297,11 @@ EOF
291 _API_call | _process_completion 297 _API_call | _process_completion
292 echo -e '\e[0m\n' 298 echo -e '\e[0m\n'
293 299
300 if [ "$VERBOSE" = true ]; then
301 tokens=$(jq -s '.[-1].usage? // empty | .total_tokens' "$cache")
302 echo -e "$tokens token used.\n"
303 fi
304
294 # Append newest message into session 305 # Append newest message into session
295 assistant_message="$(cat <<EOF 306 assistant_message="$(cat <<EOF
296{"role": "assistant", "content": $(jq -sr '.[-1].choices[0].message.content' "$cache" | jq -sR .)} 307{"role": "assistant", "content": $(jq -sr '.[-1].choices[0].message.content' "$cache" | jq -sR .)}