Skip to content

Commit f2c7516

Browse files
committed
added proper error message when api key is not set
1 parent c0ffd1d commit f2c7516

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
openai.api_key = os.getenv("OPENAI_API_KEY", "YOUR-OPENAI-KEY-HERE")
1717

18+
if not openai.api_key:
19+
# in order to use application, you need to set OPENAI_API_KEY
20+
# provide example usage
21+
print(f"{RED}In order to use this application, you need to set OPENAI_API_KEY environment variable.{RESET}
22+
\n"
23+
f"{RED}Example: export OPENAI_API_KEY=your_openai_key{RESET}")
24+
sys.exit(1)
1825

1926
def call_openai_for_command(user_message, chat_history=None):
2027
"""

0 commit comments

Comments
 (0)