Nassiraaa commited on
Commit
4ad4d2b
·
verified ·
1 Parent(s): 8f7745b

Update openai_utils.py

Browse files
Files changed (1) hide show
  1. openai_utils.py +10 -2
openai_utils.py CHANGED
@@ -1,8 +1,16 @@
1
  import os
2
  from openai import OpenAI
 
 
 
 
3
 
4
  # OpenAI configuration
5
- client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
 
 
 
 
6
  OPENAI_MODEL = "gpt-3.5-turbo"
7
 
8
  def get_ai_response(messages):
@@ -19,4 +27,4 @@ def get_ai_response(messages):
19
  return response.choices[0].message.content
20
  except Exception as e:
21
  print(f"Error getting AI response: {str(e)}")
22
- return None
 
1
  import os
2
  from openai import OpenAI
3
+ from dotenv import load_dotenv
4
+
5
+ # Load environment variables
6
+ load_dotenv()
7
 
8
  # OpenAI configuration
9
+ api_key = os.environ.get("OPENAI_API_KEY")
10
+ if not api_key:
11
+ raise ValueError("OPENAI_API_KEY environment variable is not set. Please set it and try again.")
12
+
13
+ client = OpenAI(api_key=api_key)
14
  OPENAI_MODEL = "gpt-3.5-turbo"
15
 
16
  def get_ai_response(messages):
 
27
  return response.choices[0].message.content
28
  except Exception as e:
29
  print(f"Error getting AI response: {str(e)}")
30
+ return None