From 97821ad2bbb86efac98deec4edaa1e59996694e0 Mon Sep 17 00:00:00 2001 From: OpenCo Date: Sat, 27 Jul 2024 17:28:58 +0000 Subject: [PATCH] chore: Add check for OPENAI_API_KEY environment variable before launching Startr.Team --- run.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/run.py b/run.py index 952ce84b5..96a9f8c79 100644 --- a/run.py +++ b/run.py @@ -23,7 +23,6 @@ from chatdev.chat_chain import ChatChain - def get_config(company): """ return configuration json files for ChatChain @@ -132,6 +131,28 @@ def get_config(company): # Parse the arguments args = parser.parse_args() +# Detect if API key is set in the environment and if not, print a warning and exit +if 'OPENAI_API_KEY' not in os.environ: + #Color print Blue + print("\033[94m \n") + print("""Warning: OPENAI_API_KEY environment variable is not set. + \033[0m + Please set the key before launching Startr.Team. + + To set the API key, run the following command in your terminal: + + export OPENAI_API_KEY="your-api-key-here" + + To make the change permanent, add the command to your shell profile file (e.g. ~/.bashrc). + Or to you loacl .env file. + + If you don't have an API key, you can get one at https://platform.openai.com/signup + + \033[94m \n + TODO: Alternatively use GROQ API key. + \033[0m \n + """) + sys.exit(1) # Start ChatDev