Spaces:
Runtime error
Runtime error
update
Browse files- Answering_Agent.py +29 -3
Answering_Agent.py
CHANGED
@@ -12,11 +12,37 @@ class Answering_Agent:
|
|
12 |
return "Document content for ID " + doc_id
|
13 |
|
14 |
def is_relevant(self, query, context_texts, history_str):
|
15 |
-
#
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
return any(keyword in context for keyword in keywords)
|
19 |
|
|
|
20 |
def generate_response(self, query, docs, conv_history, k=5, mode="chatty"):
|
21 |
# Concatenate the contents of the top k relevant documents
|
22 |
context_texts = "\n\n".join([f"Context {idx + 1}: {result[2]}" for idx, result in enumerate(docs)])
|
|
|
12 |
return "Document content for ID " + doc_id
|
13 |
|
14 |
def is_relevant(self, query, context_texts, history_str):
|
15 |
+
# Define a list of common stop words
|
16 |
+
stop_words = set([
|
17 |
+
"the", "what", "is", "are", "in", "of", "on", "for", "and", "a", "to",
|
18 |
+
"an", "by", "as", "at", "about", "above", "after", "again", "against",
|
19 |
+
"all", "am", "an", "any", "aren't", "as", "at", "be", "because", "been",
|
20 |
+
"before", "being", "below", "between", "both", "but", "by", "could",
|
21 |
+
"couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "don't",
|
22 |
+
"down", "during", "each", "few", "for", "from", "further", "had", "hadn't",
|
23 |
+
"has", "hasn't", "have", "haven't", "having", "he", "he'd", "he'll", "he's",
|
24 |
+
"her", "here", "here's", "hers", "herself", "him", "himself", "his", "how",
|
25 |
+
"how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "isn't",
|
26 |
+
"it", "it's", "its", "itself", "let's", "me", "more", "most", "mustn't",
|
27 |
+
"my", "myself", "no", "nor", "not", "of", "off", "on", "once", "only", "or",
|
28 |
+
"other", "ought", "our", "ours", "ourselves", "out", "over", "own", "same",
|
29 |
+
"shan't", "she", "she'd", "she'll", "she's", "should", "shouldn't", "so",
|
30 |
+
"some", "such", "than", "that", "that's", "the", "their", "theirs",
|
31 |
+
"them", "themselves", "then", "there", "there's", "these", "they", "they'd",
|
32 |
+
"they'll", "they're", "they've", "this", "those", "through", "to", "too",
|
33 |
+
"under", "until", "up", "very", "was", "wasn't", "we", "we'd", "we'll",
|
34 |
+
"we're", "we've", "were", "weren't", "what", "what's", "when", "when's",
|
35 |
+
"where", "where's", "which", "while", "who", "who's", "whom", "why",
|
36 |
+
"why's", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll",
|
37 |
+
"you're", "you've", "your", "yours", "yourself", "yourselves"
|
38 |
+
])
|
39 |
+
|
40 |
+
# Filter out stop words and split query into keywords
|
41 |
+
keywords = [word for word in query.lower().split() if word not in stop_words]
|
42 |
+
context = context_texts.lower()
|
43 |
return any(keyword in context for keyword in keywords)
|
44 |
|
45 |
+
|
46 |
def generate_response(self, query, docs, conv_history, k=5, mode="chatty"):
|
47 |
# Concatenate the contents of the top k relevant documents
|
48 |
context_texts = "\n\n".join([f"Context {idx + 1}: {result[2]}" for idx, result in enumerate(docs)])
|