Spaces:
Sleeping
Sleeping
Update rag.py (#5)
Browse files- Update rag.py (c037e4581737c0338b3e981978ddde5af6ae5574)
Co-authored-by: Prerna Aneja <[email protected]>
rag.py
CHANGED
@@ -39,13 +39,17 @@ class FinancialChatbot:
|
|
39 |
"attack", "genocide", "mass shooting", "credit card number"
|
40 |
]
|
41 |
|
|
|
|
|
|
|
|
|
42 |
# Relevance threshold
|
43 |
self.min_similarity_threshold = 0.7
|
44 |
|
45 |
def moderate_query(self, query):
|
46 |
"""Check if the query contains inappropriate words."""
|
47 |
query_lower = query.lower()
|
48 |
-
for word in self.BLOCKED_WORDS:
|
49 |
if word in query_lower:
|
50 |
return False # Block query
|
51 |
return True # Allow query
|
@@ -98,6 +102,12 @@ class FinancialChatbot:
|
|
98 |
result[:] = ["Hi, how can I help you?", 1.0]
|
99 |
return
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
if not self.moderate_query(query):
|
102 |
result[:] = ["I'm unable to process your request due to inappropriate language.", 0.0]
|
103 |
return
|
|
|
39 |
"attack", "genocide", "mass shooting", "credit card number"
|
40 |
]
|
41 |
|
42 |
+
self.NON_RELEVANT_WORDS = [
|
43 |
+
"France", "country", "rainbow", "water"
|
44 |
+
]
|
45 |
+
|
46 |
# Relevance threshold
|
47 |
self.min_similarity_threshold = 0.7
|
48 |
|
49 |
def moderate_query(self, query):
|
50 |
"""Check if the query contains inappropriate words."""
|
51 |
query_lower = query.lower()
|
52 |
+
for word in self.BLOCKED_WORDS :
|
53 |
if word in query_lower:
|
54 |
return False # Block query
|
55 |
return True # Allow query
|
|
|
102 |
result[:] = ["Hi, how can I help you?", 1.0]
|
103 |
return
|
104 |
|
105 |
+
query_lower = query.lower()
|
106 |
+
for word in self.NON_RELEVANT_WORDS :
|
107 |
+
result[:] = ["No relevant information found.", 0.0]
|
108 |
+
return
|
109 |
+
|
110 |
+
|
111 |
if not self.moderate_query(query):
|
112 |
result[:] = ["I'm unable to process your request due to inappropriate language.", 0.0]
|
113 |
return
|