Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenAI API key for local models #14

Merged
merged 1 commit into from Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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