From d68c4038b1dbfd745c6103f99346b65ee36a39b7 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sat, 25 Mar 2023 23:50:20 +0800 Subject: Update --- bin/gpt/gpt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'bin/gpt') 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: your latest prompt input. (By default, API calls use the whole previous chats, which is not friendly to token usage) + -v|--verbose If set, print token usage after each completion. + * The other arguments would be treated as message content. If no message is specified, user should input content by hands. If STDIN is given, it would be append to the end of message. @@ -86,7 +88,7 @@ _print_leave_message(){ tokens=$(jq '.usage? // empty | .total_tokens' "$cache" | paste -sd+ | bc) echo -en "${tokens:-0} tokens used. " fi - echo Session is cached in: "$cache" + echo Session is cached in "$cache" exit 0 } @@ -218,6 +220,10 @@ while [ "$#" -gt 0 ]; do context=$2 shift 2 ;; + -v|--verbose) + VERBOSE=true + shift 1 + ;; -h|--help) _print_helper_message exit 0 @@ -291,6 +297,11 @@ EOF _API_call | _process_completion echo -e '\e[0m\n' + if [ "$VERBOSE" = true ]; then + tokens=$(jq -s '.[-1].usage? // empty | .total_tokens' "$cache") + echo -e "$tokens token used.\n" + fi + # Append newest message into session assistant_message="$(cat <