midrees2806 commited on
Commit
95c946c
·
verified ·
1 Parent(s): 0524077

Update rag.py

Browse files
Files changed (1) hide show
  1. rag.py +18 -9
rag.py CHANGED
@@ -9,6 +9,8 @@ import numpy as np
9
  from dotenv import load_dotenv
10
  import os
11
  import pandas as pd # <-- Required for Excel logging
 
 
12
 
13
  # Load environment variables
14
  load_dotenv()
@@ -63,15 +65,22 @@ def get_best_answer(user_input):
63
 
64
  # ✏️ If not matched well, log to Excel
65
  if best_score < 0.65:
66
- file_path = "unmatched_queries.xlsx"
67
- if os.path.exists(file_path):
68
- try:
69
- df = pd.read_excel(file_path)
70
- new_row = {"Unmatched Queries": user_input}
71
- df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
72
- df.to_excel(file_path, index=False)
73
- except Exception as e:
74
- print(f"Error updating unmatched_queries.xlsx: {e}")
 
 
 
 
 
 
 
75
 
76
  # 🧠 Prompt construction
77
  if best_score >= 0.65:
 
9
  from dotenv import load_dotenv
10
  import os
11
  import pandas as pd # <-- Required for Excel logging
12
+ import csv
13
+ import os
14
 
15
  # Load environment variables
16
  load_dotenv()
 
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: