Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -31,6 +31,9 @@ collection_name = os.getenv("MONGO_COLLECTION", "files_collection")
|
|
31 |
index_name = os.getenv("MONGO_VECTOR_INDEX", "vector_index")
|
32 |
|
33 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
34 |
|
35 |
# MONGO_URI = f"mongodb+srv://{user}:{password}@{cluster}/{db_name}?retryWrites=true&w=majority"
|
36 |
MONGO_URI = f"mongodb+srv://{user}:{password}@{cluster}/{db_name}?retryWrites=true&w=majority&tls=true&tlsAllowInvalidCertificates=true"
|
@@ -255,7 +258,10 @@ PROMPTS:
|
|
255 |
)
|
256 |
|
257 |
if use_openai:
|
258 |
-
|
|
|
|
|
|
|
259 |
try:
|
260 |
response = openai.ChatCompletion.create(
|
261 |
model="gpt-3.5-turbo",
|
@@ -343,11 +349,10 @@ tokenizer, model = load_local_model()
|
|
343 |
|
344 |
def generate_response(input_dict):
|
345 |
if USE_OPENAI:
|
346 |
-
|
347 |
-
openai_key = os.getenv("OPENAI_API_KEY")
|
348 |
-
if not openai_key:
|
349 |
st.error("❌ OPENAI_API_KEY is not set.")
|
350 |
-
return "⚠️
|
|
|
351 |
|
352 |
import openai
|
353 |
openai.api_key = openai_key
|
|
|
31 |
index_name = os.getenv("MONGO_VECTOR_INDEX", "vector_index")
|
32 |
|
33 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
34 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "").strip()
|
35 |
+
if OPENAI_API_KEY:
|
36 |
+
openai.api_key = OPENAI_API_KEY
|
37 |
|
38 |
# MONGO_URI = f"mongodb+srv://{user}:{password}@{cluster}/{db_name}?retryWrites=true&w=majority"
|
39 |
MONGO_URI = f"mongodb+srv://{user}:{password}@{cluster}/{db_name}?retryWrites=true&w=majority&tls=true&tlsAllowInvalidCertificates=true"
|
|
|
258 |
)
|
259 |
|
260 |
if use_openai:
|
261 |
+
if not openai.api_key:
|
262 |
+
st.error("❌ OPENAI_API_KEY is not set.")
|
263 |
+
return "⚠️ OpenAI key missing."
|
264 |
+
|
265 |
try:
|
266 |
response = openai.ChatCompletion.create(
|
267 |
model="gpt-3.5-turbo",
|
|
|
349 |
|
350 |
def generate_response(input_dict):
|
351 |
if USE_OPENAI:
|
352 |
+
if not openai.api_key:
|
|
|
|
|
353 |
st.error("❌ OPENAI_API_KEY is not set.")
|
354 |
+
return "⚠️ OpenAI key missing."
|
355 |
+
|
356 |
|
357 |
import openai
|
358 |
openai.api_key = openai_key
|