Spaces:
Sleeping
Sleeping
Update rag.py
Browse files
rag.py
CHANGED
|
@@ -63,24 +63,24 @@ def get_best_answer(user_input):
|
|
| 63 |
best_match_idx = similarities.argmax().item()
|
| 64 |
best_score = similarities[best_match_idx].item()
|
| 65 |
|
| 66 |
-
# ✏️ If not matched well, log to
|
| 67 |
if best_score < 0.65:
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
# 🧠 Prompt construction
|
| 86 |
if best_score >= 0.65:
|
|
@@ -114,3 +114,4 @@ def get_best_answer(user_input):
|
|
| 114 |
🌐 ue.edu.pk"""
|
| 115 |
|
| 116 |
return response
|
|
|
|
|
|
| 63 |
best_match_idx = similarities.argmax().item()
|
| 64 |
best_score = similarities[best_match_idx].item()
|
| 65 |
|
| 66 |
+
# ✏️ If not matched well, log to CSV
|
| 67 |
if best_score < 0.65:
|
| 68 |
+
file_path = "unmatched_queries.csv"
|
| 69 |
+
|
| 70 |
+
# Check if file exists
|
| 71 |
+
if not os.path.exists(file_path):
|
| 72 |
+
# Create file and write header
|
| 73 |
+
with open(file_path, mode="w", newline="", encoding="utf-8") as file:
|
| 74 |
+
writer = csv.writer(file)
|
| 75 |
+
writer.writerow(["Unmatched Queries"])
|
| 76 |
+
|
| 77 |
+
try:
|
| 78 |
+
# Append new query
|
| 79 |
+
with open(file_path, mode="a", newline="", encoding="utf-8") as file:
|
| 80 |
+
writer = csv.writer(file)
|
| 81 |
+
writer.writerow([user_input])
|
| 82 |
+
except Exception as e:
|
| 83 |
+
print(f"Error writing to unmatched_queries.csv: {e}")
|
| 84 |
|
| 85 |
# 🧠 Prompt construction
|
| 86 |
if best_score >= 0.65:
|
|
|
|
| 114 |
🌐 ue.edu.pk"""
|
| 115 |
|
| 116 |
return response
|
| 117 |
+
|