ankanghosh commited on
Commit
486bb98
·
verified ·
1 Parent(s): 7544cdf

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +6 -6
utils.py CHANGED
@@ -82,9 +82,9 @@ def setup_openai_auth():
82
  Setup OpenAI API authentication using various methods.
83
 
84
  This function tries multiple authentication methods in order of preference:
85
- 1. Standard environment variable (OPENAI_API_KEY)
86
- 2. HF Spaces environment variable (OPENAI_KEY) - this is our primary method,
87
  with API key stored exclusively in HF Spaces secrets for deployment
 
88
  3. Streamlit secrets (openai_api_key) - fallback method
89
 
90
  Note: In production, we exclusively use HF Spaces secrets for storing the OpenAI API key.
@@ -95,16 +95,16 @@ def setup_openai_auth():
95
  Exception: For any authentication errors
96
  """
97
  try:
98
- # Option 1: Standard environment variable
99
  if "OPENAI_API_KEY" in os.environ:
100
  openai.api_key = os.getenv("OPENAI_API_KEY")
101
- print("✅ Using OpenAI API key from environment variable")
102
  return
103
 
104
- # Option 2: HF Spaces environment variable with different name
105
  elif "OPENAI_KEY" in os.environ:
106
  openai.api_key = os.getenv("OPENAI_KEY")
107
- print("✅ Using OpenAI API key from HF Spaces environment variable")
108
  return
109
 
110
  # Option 3: Streamlit secrets
 
82
  Setup OpenAI API authentication using various methods.
83
 
84
  This function tries multiple authentication methods in order of preference:
85
+ 1. HF Spaces environment variable (OPENAI_API_KEY) - this is our primary method,
 
86
  with API key stored exclusively in HF Spaces secrets for deployment
87
+ 2. Standard local environment variable (OPENAI_KEY)
88
  3. Streamlit secrets (openai_api_key) - fallback method
89
 
90
  Note: In production, we exclusively use HF Spaces secrets for storing the OpenAI API key.
 
95
  Exception: For any authentication errors
96
  """
97
  try:
98
+ # Option 1: HF Spaces environment variable (primary method)
99
  if "OPENAI_API_KEY" in os.environ:
100
  openai.api_key = os.getenv("OPENAI_API_KEY")
101
+ print("✅ Using OpenAI API key from HF Spaces environment variable")
102
  return
103
 
104
+ # Option 2: Standard local environment variable
105
  elif "OPENAI_KEY" in os.environ:
106
  openai.api_key = os.getenv("OPENAI_KEY")
107
+ print("✅ Using OpenAI API key from standard local environment variable")
108
  return
109
 
110
  # Option 3: Streamlit secrets