diff --git a/chatgpt.sh b/chatgpt.sh index 81df29a..bfe1b62 100755 --- a/chatgpt.sh +++ b/chatgpt.sh @@ -12,9 +12,13 @@ CHATGPT_CYAN_LABEL="\033[36mchatgpt \033[0m" PROCESSING_LABEL="\n\033[90mProcessing... \033[0m\033[0K\r" OVERWRITE_PROCESSING_LINE=" \033[0K\r" -if [[ -z "$OPENAI_KEY" ]]; then - echo "You need to set your OPENAI_KEY to use this script" - echo "You can set it temporarily by running this on your terminal: export OPENAI_KEY=YOUR_KEY_HERE" +if [[ -z "$OPENAI_API_KEY" ]]; then + if [[ -n "$OPENAI_KEY" ]]; then + OPENAI_API_KEY="$OPENAI_KEY" + echo "OPENAI_KEY has been deprecated. Change it to OPENAI_API_KEY." + fi + echo "You need to set your OPENAI_API_KEY to use this script" + echo "You can set it temporarily by running this on your terminal: export OPENAI_API_KEY=YOUR_KEY_HERE" exit 1 fi @@ -83,7 +87,7 @@ handle_error() { list_models() { models_response=$(curl https://api.openai.com/v1/models \ -sS \ - -H "Authorization: Bearer $OPENAI_KEY") + -H "Authorization: Bearer $OPENAI_API_KEY") handle_error "$models_response" models_data=$(echo $models_response | jq -r -C '.data[] | {id, owned_by, created}') echo -e "$OVERWRITE_PROCESSING_LINE" @@ -97,7 +101,7 @@ request_to_completions() { curl https://api.openai.com/v1/completions \ -sS \ -H 'Content-Type: application/json' \ - -H "Authorization: Bearer $OPENAI_KEY" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "'"$MODEL"'", "prompt": "'"$prompt"'", @@ -113,7 +117,7 @@ request_to_image() { image_response=$(curl https://api.openai.com/v1/images/generations \ -sS \ -H 'Content-Type: application/json' \ - -H "Authorization: Bearer $OPENAI_KEY" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "prompt": "'"${prompt#*image:}"'", "n": 1, @@ -130,7 +134,7 @@ request_to_chat() { curl https://api.openai.com/v1/chat/completions \ -sS \ -H 'Content-Type: application/json' \ - -H "Authorization: Bearer $OPENAI_KEY" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "'"$MODEL"'", "messages": [ @@ -369,7 +373,7 @@ while $running; do elif [[ "$prompt" =~ ^model: ]]; then models_response=$(curl https://api.openai.com/v1/models \ -sS \ - -H "Authorization: Bearer $OPENAI_KEY") + -H "Authorization: Bearer $OPENAI_API_KEY") handle_error "$models_response" model_data=$(echo $models_response | jq -r -C '.data[] | select(.id=="'"${prompt#*model:}"'")') echo -e "$OVERWRITE_PROCESSING_LINE"