-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa529ca
commit 27e6eac
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os | ||
from flask import current_app | ||
from server.common.utils.aws_secret_utils import get_secret_key | ||
|
||
|
||
def get_openai_api_key(): | ||
deployment_stage = os.getenv("DEPLOYMENT_STAGE", "test") | ||
if deployment_stage == "test": | ||
return os.getenv("OPENAI_API_KEY") | ||
return get_secret_key(f"{deployment_stage}/explorer/agent", region_name="us-west-2")["OPENAI_API_KEY"] | ||
|
||
|
||
def get_cached_openai_api_key(): | ||
"""Get OpenAI API key from cache or fetch it if not cached""" | ||
if not hasattr(current_app, "openai_api_key"): | ||
current_app.openai_api_key = get_openai_api_key() | ||
return current_app.openai_api_key |