poemsforaphrodite commited on
Commit
1b65ecd
1 Parent(s): d25d88b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -22,7 +22,8 @@ st.set_page_config(layout="wide")
22
 
23
  load_dotenv()
24
 
25
- client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
 
26
 
27
  pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY"))
28
 
@@ -32,16 +33,17 @@ index = pc.Index(index_name)
32
  mongo_uri = os.getenv("MONGODB_URI")
33
 
34
  try:
35
- client = MongoClient(mongo_uri, serverSelectionTimeoutMS=5000)
36
- client.server_info()
37
- db = client['lyca']
 
38
  sim_swap_collection = db['sim_swap_requests']
39
  except ConnectionFailure:
40
  st.error("Failed to connect to MongoDB. Please check your connection and try again later.")
41
  sim_swap_collection = None
42
 
43
  def get_embedding(text):
44
- response = client.embeddings.create(input=text, model="text-embedding-3-large")
45
  return response.data[0].embedding
46
 
47
  def process_web_link(url):
@@ -154,7 +156,7 @@ def load_lyca_mobile_data():
154
  return "Lyca Mobile data loaded into vector database"
155
 
156
  def general_conversation(message):
157
- response = client.chat.completions.create(
158
  model="gpt-4o-mini",
159
  messages=[
160
  {"role": "system", "content": "You are a helpful assistant for Lyca Mobile customers. If you don't know the answer, politely say so."},
@@ -220,7 +222,7 @@ def chat_with_ai(message):
220
  {"role": "user", "content": message}
221
  ]
222
 
223
- response = client.chat.completions.create(
224
  model="gpt-4o-mini",
225
  messages=messages
226
  )
 
22
 
23
  load_dotenv()
24
 
25
+ # Renamed OpenAI client to avoid collision
26
+ openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
27
 
28
  pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY"))
29
 
 
33
  mongo_uri = os.getenv("MONGODB_URI")
34
 
35
  try:
36
+ # Renamed MongoDB client to avoid collision
37
+ mongo_client = MongoClient(mongo_uri, serverSelectionTimeoutMS=5000)
38
+ mongo_client.server_info()
39
+ db = mongo_client['lyca']
40
  sim_swap_collection = db['sim_swap_requests']
41
  except ConnectionFailure:
42
  st.error("Failed to connect to MongoDB. Please check your connection and try again later.")
43
  sim_swap_collection = None
44
 
45
  def get_embedding(text):
46
+ response = openai_client.embeddings.create(input=text, model="text-embedding-3-large")
47
  return response.data[0].embedding
48
 
49
  def process_web_link(url):
 
156
  return "Lyca Mobile data loaded into vector database"
157
 
158
  def general_conversation(message):
159
+ response = openai_client.chat.completions.create(
160
  model="gpt-4o-mini",
161
  messages=[
162
  {"role": "system", "content": "You are a helpful assistant for Lyca Mobile customers. If you don't know the answer, politely say so."},
 
222
  {"role": "user", "content": message}
223
  ]
224
 
225
+ response = openai_client.chat.completions.create(
226
  model="gpt-4o-mini",
227
  messages=messages
228
  )