From f8f4b2722b3cd131e4af573c9d22e47acb831383 Mon Sep 17 00:00:00 2001 From: Haseeb Date: Tue, 12 Mar 2024 14:18:29 +0400 Subject: [PATCH] Add OpenAI API key for local models --- libs/interpreter_lib.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/interpreter_lib.py b/libs/interpreter_lib.py index 2a486b3..1c63b81 100644 --- a/libs/interpreter_lib.py +++ b/libs/interpreter_lib.py @@ -106,6 +106,18 @@ def initialize_client(self): # skip init client for local models.(Bug#10 https://github.com/haseeb-heaven/code-interpreter/issues/10) if 'local' in self.INTERPRETER_MODEL: self.logger.info(f"Skipping client initialization for local model.") + # Add OpenAI API key if not present in the environment variables. (https://github.com/haseeb-heaven/code-interpreter/issues/13) + api_key = os.environ['OPEN_AI_API_KEY'] + + if api_key: + self.logger.info(f"Using local API key from environment variables.") + + if api_key is None: + load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env")) + api_key = os.getenv('OPEN_AI_API_KEY') + if api_key is None: + self.logger.info(f"Setting default local API key for local models.") + os.environ['OPEN_AI_API_KEY'] = "sk-1234567890" # Setting default API key for local models. return self.logger.info(f"Using model {hf_model_name}")