-
Notifications
You must be signed in to change notification settings - Fork 0
/
DLAIUtils.py
27 lines (22 loc) · 776 Bytes
/
DLAIUtils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import sys
from dotenv import load_dotenv, find_dotenv
class Utils:
def __init__(self):
pass
def create_dlai_index_name(self, index_name):
openai_key = ''
if self.is_colab(): # google colab
from google.colab import userdata
openai_key = userdata.get("OPENAI_API_KEY")
else: # jupyter notebook
openai_key = self.get_openai_api_key() # os.getenv("OPENAI_API_KEY")
return f'{index_name}-{openai_key[-36:].lower().replace("_", "-")}'
def is_colab(self):
return 'google.colab' in sys.modules
def get_openai_api_key(self):
_ = load_dotenv(find_dotenv())
return os.getenv("OPENAI_API_KEY")
def get_pinecone_api_key(self):
_ = load_dotenv(find_dotenv())
return os.getenv("PINECONE_API_KEY")