midrees2806 commited on
Commit
f8b9b57
Β·
verified Β·
1 Parent(s): 210347b

Update rag.py

Browse files
Files changed (1) hide show
  1. rag.py +18 -17
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 Excel
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,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
+