diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2023-03-25 13:17:03 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2023-03-25 13:17:03 +0800 |
commit | 5ae55cd1e29473e3e39811ed07d6e259fe15488c (patch) | |
tree | 7cb5dcead078923652eba60a239e6d34cc769673 | |
parent | ad4681f11715e76d68ed2b31701ccb2fce02a4c1 (diff) |
Update
-rwxr-xr-x | bin/gpt/gpt | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/bin/gpt/gpt b/bin/gpt/gpt index c3941a3..d125204 100755 --- a/bin/gpt/gpt +++ b/bin/gpt/gpt | |||
@@ -74,7 +74,7 @@ EOF | |||
74 | 74 | ||
75 | # Message when user exit prompt | 75 | # Message when user exit prompt |
76 | _print_leave_message(){ | 76 | _print_leave_message(){ |
77 | echo -en "\nChat ends. " | 77 | echo -en "\n\nChat ends. " |
78 | if [ "$stream" = false ]; then | 78 | if [ "$stream" = false ]; then |
79 | tokens=$(jq '.usage? // empty | .total_tokens' "$cache" | paste -sd+ | bc) | 79 | tokens=$(jq '.usage? // empty | .total_tokens' "$cache" | paste -sd+ | bc) |
80 | echo -en "${tokens:-0} tokens used. " | 80 | echo -en "${tokens:-0} tokens used. " |
@@ -121,7 +121,12 @@ _get_content() { | |||
121 | # Read content it from terminal | 121 | # Read content it from terminal |
122 | while true; do | 122 | while true; do |
123 | read -e -r -p "Let's Chat: " content </dev/tty | 123 | read -e -r -p "Let's Chat: " content </dev/tty |
124 | [[ "$content" =~ ^\. ]] && echo && _configure_options && echo -e '\n======\n' && continue | 124 | if [[ "$content" =~ ^\. ]]; then |
125 | echo -e '\n======\n' | ||
126 | _configure_options | ||
127 | echo -e '\n======\n' | ||
128 | continue | ||
129 | fi | ||
125 | [ -n "$content" ] && break | 130 | [ -n "$content" ] && break |
126 | done | 131 | done |
127 | elif [[ "$count" -eq 0 && -z "${content}${data}" ]]; then | 132 | elif [[ "$count" -eq 0 && -z "${content}${data}" ]]; then |
@@ -256,14 +261,10 @@ EOF | |||
256 | # Append request body into cache | 261 | # Append request body into cache |
257 | echo "$body" >>"$cache" | 262 | echo "$body" >>"$cache" |
258 | 263 | ||
259 | # Add an empty line between prompt and response | 264 | # Use Yellow color to print completion from GPT |
260 | echo -e '\n------\n' | 265 | echo -en '\n\e[33m' |
261 | |||
262 | # API call | ||
263 | # Save original response into cache file | ||
264 | # And only print content of message | ||
265 | _API_call | _process_completion | 266 | _API_call | _process_completion |
266 | echo -e "\n\n======\n" | 267 | echo -e '\e[0m' |
267 | 268 | ||
268 | # Append newest message into session | 269 | # Append newest message into session |
269 | assistant_message="$(cat <<EOF | 270 | assistant_message="$(cat <<EOF |