diff options
-rwxr-xr-x | bin/gpt/gpt | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/bin/gpt/gpt b/bin/gpt/gpt index aa770bb..374a707 100755 --- a/bin/gpt/gpt +++ b/bin/gpt/gpt | |||
@@ -333,11 +333,24 @@ EOF | |||
333 | # Append request body into cache | 333 | # Append request body into cache |
334 | echo "$body" >>"$cache" | 334 | echo "$body" >>"$cache" |
335 | 335 | ||
336 | # Use Yellow color to print completion from GPT | 336 | # Run API call in coprocess |
337 | echo -en '\e[33m' | 337 | coproc API { |
338 | _API_call | _process_completion | 338 | _API_call | _process_completion |
339 | echo -e '\e[0m\n' | 339 | } |
340 | 340 | ||
341 | # While API call does not end, print indicator onto terminal | ||
342 | while ps ${API_PID} &>/dev/null; do | ||
343 | printf '.' | ||
344 | sleep 1 | ||
345 | done & | ||
346 | |||
347 | # Read response of API call from coprocess | ||
348 | response=$( cat <&"${API[0]}" ) | ||
349 | |||
350 | # Use Yellow color to print response | ||
351 | echo -e "\r\e[K\e[33m$response\e[0m\n" | ||
352 | |||
353 | # Print how many tokens used (if VERBOSE is set) | ||
341 | if [ "$VERBOSE" = true ]; then | 354 | if [ "$VERBOSE" = true ]; then |
342 | tokens=$(jq -s '.[-1].usage? // empty | .total_tokens' "$cache") | 355 | tokens=$(jq -s '.[-1].usage? // empty | .total_tokens' "$cache") |
343 | echo -e "$tokens token used.\n" | 356 | echo -e "$tokens token used.\n" |