Skip to content

Commit

Permalink
rename(OPENAI_KEY): OPENAI_API_KEY is standardised across projects
Browse files Browse the repository at this point in the history
  • Loading branch information
camAtGitHub committed Apr 20, 2023
1 parent 24fc6bf commit 1cf6d04
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions chatgpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PROCESSING_LABEL="\n\033[90mProcessing... \033[0m\033[0K\r"
OVERWRITE_PROCESSING_LINE=" \033[0K\r"


if [[ -z "$OPENAI_KEY" ]]; then
if [[ -z "$OPENAI_API_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"
exit 1
Expand Down Expand Up @@ -84,7 +84,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"
Expand All @@ -98,7 +98,7 @@ request_to_completions() {
response=$(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": "'"${request_prompt}"'",
Expand All @@ -114,7 +114,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,
Expand All @@ -129,7 +129,7 @@ request_to_chat() {
response=$(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": [
Expand Down Expand Up @@ -374,7 +374,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"
Expand Down

0 comments on commit 1cf6d04

Please sign in to comment.