Skip to content

Commit 3234a04

Browse files
committed
Check for API Keys instead of just crash
1 parent f4742cd commit 3234a04

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ChatGPT_Bear/assistant.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import threading
66
import os
7+
import sys
78

89
from datetime import datetime, timedelta
910
from queue import Queue
@@ -48,6 +49,12 @@
4849
speech_key = os.environ.get("SPEECH_KEY")
4950
service_region = os.environ.get("SPEECH_REGION")
5051

52+
if openai.api_key is None or speech_key is None or service_region is None:
53+
print(
54+
"Please set the OPENAI_API_KEY, SPEECH_KEY, and SPEECH_REGION environment variables first."
55+
)
56+
sys.exit(1)
57+
5158
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
5259
speech_config.speech_synthesis_voice_name = AZURE_SPEECH_VOICE
5360

0 commit comments

Comments
 (0)