Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
atarashansky committed Dec 12, 2024
1 parent aa529ca commit 27e6eac
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions server/common/openai_utils.py
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

0 comments on commit 27e6eac

Please sign in to comment.