Skip to content

Commit

Permalink
Merge pull request #14 from haseeb-heaven/local-model-api-key-bug-13
Browse files Browse the repository at this point in the history
Add OpenAI API key for local models
  • Loading branch information
haseeb-heaven committed Mar 12, 2024
2 parents d3a252e + f8f4b27 commit 553ee1e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libs/interpreter_lib.py
Expand Up @@ -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}")
Expand Down

0 comments on commit 553ee1e

Please sign in to comment.