Spaces:
Sleeping
Sleeping
Update rag.py
Browse files
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 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|