Spaces:
Paused
Paused
looker01202
commited on
Commit
·
d9024e6
1
Parent(s):
99b3f8f
Gemini changes added 4
Browse files
app.py
CHANGED
@@ -200,11 +200,27 @@ def chat(message, history, hotel_id):
|
|
200 |
knowledge_dir = "knowledge"
|
201 |
available_hotels = []
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
# Check if the knowledge directory exists and is a directory
|
204 |
if os.path.isdir(knowledge_dir):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
potential_ids = set()
|
206 |
# First pass: collect all potential base names from .txt files
|
207 |
-
for filename in os.listdir(knowledge_dir):
|
208 |
if filename.endswith(".txt") and not filename.startswith('.'): # Ignore hidden files
|
209 |
if filename.endswith("-system.txt"):
|
210 |
# Extract base name from system prompt file
|
@@ -218,10 +234,19 @@ if os.path.isdir(knowledge_dir):
|
|
218 |
|
219 |
# Second pass: check if both files exist for each potential ID
|
220 |
# Sort the potential IDs for consistent dropdown order
|
|
|
221 |
for hotel_id in sorted(list(potential_ids)):
|
222 |
main_file = os.path.join(knowledge_dir, f"{hotel_id}.txt")
|
223 |
system_file = os.path.join(knowledge_dir, f"{hotel_id}-system.txt")
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
# Check if BOTH the main knowledge file AND the system prompt file exist
|
226 |
if os.path.exists(main_file) and os.path.exists(system_file):
|
227 |
available_hotels.append(hotel_id)
|
@@ -230,9 +255,15 @@ if os.path.isdir(knowledge_dir):
|
|
230 |
# Optional: Print a warning if one file exists but not the other
|
231 |
if os.path.exists(main_file) or os.path.exists(system_file):
|
232 |
print(f"⚠️ Skipping '{hotel_id}': Missing either '{hotel_id}.txt' or '{hotel_id}-system.txt'")
|
|
|
|
|
|
|
|
|
|
|
233 |
|
234 |
else:
|
235 |
-
print(f"❌ Error: Knowledge directory '{knowledge_dir}' not found or is not a directory.")
|
|
|
236 |
|
237 |
# Handle case where no valid hotels were found
|
238 |
if not available_hotels:
|
|
|
200 |
knowledge_dir = "knowledge"
|
201 |
available_hotels = []
|
202 |
|
203 |
+
# --- Add Debugging ---
|
204 |
+
print(f"DEBUG: Current Working Directory: {os.getcwd()}")
|
205 |
+
print(f"DEBUG: Checking for knowledge directory at relative path: '{knowledge_dir}'")
|
206 |
+
knowledge_dir_abs = os.path.abspath(knowledge_dir)
|
207 |
+
print(f"DEBUG: Absolute path for knowledge directory: '{knowledge_dir_abs}'")
|
208 |
+
# --- End Debugging ---
|
209 |
+
|
210 |
# Check if the knowledge directory exists and is a directory
|
211 |
if os.path.isdir(knowledge_dir):
|
212 |
+
# --- Add Debugging ---
|
213 |
+
try:
|
214 |
+
print(f"DEBUG: Listing contents of '{knowledge_dir_abs}':")
|
215 |
+
dir_contents = os.listdir(knowledge_dir)
|
216 |
+
print(f"DEBUG: Found files/dirs: {dir_contents}")
|
217 |
+
except Exception as e:
|
218 |
+
print(f"DEBUG: Error listing directory '{knowledge_dir_abs}': {e}")
|
219 |
+
# --- End Debugging ---
|
220 |
+
|
221 |
potential_ids = set()
|
222 |
# First pass: collect all potential base names from .txt files
|
223 |
+
for filename in os.listdir(knowledge_dir): # Assuming listdir succeeded if we got here
|
224 |
if filename.endswith(".txt") and not filename.startswith('.'): # Ignore hidden files
|
225 |
if filename.endswith("-system.txt"):
|
226 |
# Extract base name from system prompt file
|
|
|
234 |
|
235 |
# Second pass: check if both files exist for each potential ID
|
236 |
# Sort the potential IDs for consistent dropdown order
|
237 |
+
print(f"DEBUG: Potential hotel IDs found: {sorted(list(potential_ids))}") # Debug potential IDs
|
238 |
for hotel_id in sorted(list(potential_ids)):
|
239 |
main_file = os.path.join(knowledge_dir, f"{hotel_id}.txt")
|
240 |
system_file = os.path.join(knowledge_dir, f"{hotel_id}-system.txt")
|
241 |
|
242 |
+
# --- Add Debugging ---
|
243 |
+
main_file_abs = os.path.abspath(main_file)
|
244 |
+
system_file_abs = os.path.abspath(system_file)
|
245 |
+
print(f"DEBUG: Checking pair for ID '{hotel_id}':")
|
246 |
+
print(f"DEBUG: Main file: '{main_file_abs}' -> Exists? {os.path.exists(main_file)}")
|
247 |
+
print(f"DEBUG: System file: '{system_file_abs}' -> Exists? {os.path.exists(system_file)}")
|
248 |
+
# --- End Debugging ---
|
249 |
+
|
250 |
# Check if BOTH the main knowledge file AND the system prompt file exist
|
251 |
if os.path.exists(main_file) and os.path.exists(system_file):
|
252 |
available_hotels.append(hotel_id)
|
|
|
255 |
# Optional: Print a warning if one file exists but not the other
|
256 |
if os.path.exists(main_file) or os.path.exists(system_file):
|
257 |
print(f"⚠️ Skipping '{hotel_id}': Missing either '{hotel_id}.txt' or '{hotel_id}-system.txt'")
|
258 |
+
# --- Add Debugging ---
|
259 |
+
# Add an else here to catch cases where NEITHER file exists for a potential ID
|
260 |
+
elif not os.path.exists(main_file) and not os.path.exists(system_file):
|
261 |
+
print(f"DEBUG: Neither file found for potential ID '{hotel_id}' at checked paths.")
|
262 |
+
# --- End Debugging ---
|
263 |
|
264 |
else:
|
265 |
+
print(f"❌ Error: Knowledge directory '{knowledge_dir}' (abs path: '{knowledge_dir_abs}') not found or is not a directory.")
|
266 |
+
|
267 |
|
268 |
# Handle case where no valid hotels were found
|
269 |
if not available_hotels:
|