Skip to content

Commit 0a1ca89

Browse files
committed
formatting
1 parent 3ba434e commit 0a1ca89

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

chatgpt.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ CHATGPT_CYAN_LABEL="\033[36mchatgpt \033[0m"
1212
PROCESSING_LABEL="\n\033[90mProcessing... \033[0m\033[0K\r"
1313
OVERWRITE_PROCESSING_LINE=" \033[0K\r"
1414

15-
1615
if [[ -z "$OPENAI_KEY" ]]; then
1716
echo "You need to set your OPENAI_KEY to use this script"
1817
echo "You can set it temporarily by running this on your terminal: export OPENAI_KEY=YOUR_KEY_HERE"
@@ -82,13 +81,13 @@ handle_error() {
8281
# request to openAI API models endpoint. Returns a list of models
8382
# takes no input parameters
8483
list_models() {
85-
models_response=$(curl https://api.openai.com/v1/models \
86-
-sS \
87-
-H "Authorization: Bearer $OPENAI_KEY")
88-
handle_error "$models_response"
89-
models_data=$(echo $models_response | jq -r -C '.data[] | {id, owned_by, created}')
90-
echo -e "$OVERWRITE_PROCESSING_LINE"
91-
echo -e "${CHATGPT_CYAN_LABEL}This is a list of models currently available at OpenAI API:\n ${models_data}"
84+
models_response=$(curl https://api.openai.com/v1/models \
85+
-sS \
86+
-H "Authorization: Bearer $OPENAI_KEY")
87+
handle_error "$models_response"
88+
models_data=$(echo $models_response | jq -r -C '.data[] | {id, owned_by, created}')
89+
echo -e "$OVERWRITE_PROCESSING_LINE"
90+
echo -e "${CHATGPT_CYAN_LABEL}This is a list of models currently available at OpenAI API:\n ${models_data}"
9291
}
9392
# request to OpenAI API completions endpoint function
9493
# $1 should be the request prompt
@@ -301,7 +300,6 @@ if [ $BIG_PROMPT = true ]; then
301300
trap 'rm -f ${USER_INPUT}' EXIT
302301
fi
303302

304-
305303
# create history file
306304
if [ ! -f ~/.chatgpt_history ]; then
307305
touch ~/.chatgpt_history
@@ -327,13 +325,13 @@ while $running; do
327325
if [ -z "$pipe_mode_prompt" ]; then
328326
if [ $BIG_PROMPT = true ]; then
329327
echo -e "\nEnter a prompt: (Press Enter then Ctrl-D to send)"
330-
cat > "${USER_INPUT}"
328+
cat >"${USER_INPUT}"
331329
prompt=$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' "${USER_INPUT}")
332330
else
333331
echo -e "\nEnter a prompt:"
334332
read -e prompt
335333
fi
336-
if [[ ! $prompt =~ ^(exit|q)$ ]]; then
334+
if [[ ! $prompt =~ ^(exit|q)$ ]]; then
337335
echo -ne $PROCESSING_LABEL
338336
fi
339337
else
@@ -343,7 +341,7 @@ while $running; do
343341
CHATGPT_CYAN_LABEL=""
344342
fi
345343

346-
if [[ $prompt =~ ^(exit|q)$ ]]; then
344+
if [[ $prompt =~ ^(exit|q)$ ]]; then
347345
running=false
348346
elif [[ "$prompt" =~ ^image: ]]; then
349347
request_to_image "$prompt"
@@ -431,7 +429,7 @@ while $running; do
431429
if command -v glow &>/dev/null; then
432430
echo -e "${CHATGPT_CYAN_LABEL}"
433431
echo "${response_data}" | glow -
434-
#echo -e "${formatted_text}"
432+
#echo -e "${formatted_text}"
435433
else
436434
echo -e "${CHATGPT_CYAN_LABEL}${response_data}" | fold -s -w $COLUMNS
437435
fi
@@ -460,7 +458,7 @@ while $running; do
460458
echo -e "${CHATGPT_CYAN_LABEL}"
461459
echo "${response_data}" | glow -
462460
else
463-
# else remove empty lines and print
461+
# else remove empty lines and print
464462
formatted_text=$(echo "${response_data}" | sed '1,2d; s/^A://g')
465463
echo -e "${CHATGPT_CYAN_LABEL}${formatted_text}" | fold -s -w $COLUMNS
466464
fi

0 commit comments

Comments
 (0)