Skip to content

Commit 99f902d

Browse files
committed
Add new self.openai_api_key approach
1 parent fd6d493 commit 99f902d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

operate/config.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,29 @@ def __init__(self):
3636

3737
def initialize_openai(self):
3838
client = OpenAI()
39-
client.api_key = os.getenv("OPENAI_API_KEY")
39+
if self.openai_api_key:
40+
if self.verbose:
41+
print("[Config][initialize_openai] using cached openai_api_key")
42+
api_key = self.openai_api_key
43+
else:
44+
print(
45+
"[Config][initialize_openai] no cached openai_api_key, try to get from env."
46+
)
47+
api_key = os.getenv("OPENAI_API_KEY")
48+
client.api_key = api_key
4049
client.base_url = os.getenv("OPENAI_API_BASE_URL", client.base_url)
4150
return client
4251

4352
def initialize_google(self):
53+
if self.google_api_key:
54+
if self.verbose:
55+
print("[Config][initialize_google] using cached google_api_key")
56+
api_key = self.google_api_key
57+
else:
58+
print(
59+
"[Config][initialize_google] no cached google_api_key, try to get from env."
60+
)
61+
api_key = os.getenv("GOOGLE_API_KEY")
4462
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"), transport="rest")
4563
model = genai.GenerativeModel("gemini-pro-vision")
4664

0 commit comments

Comments
 (0)