imSleepy commited on
Commit
7b42316
·
verified ·
1 Parent(s): b5e1894

updated the chatbot.py ("Can you elaborate the question")

Browse files
Files changed (1) hide show
  1. chatbot.py +6 -4
chatbot.py CHANGED
@@ -35,10 +35,6 @@ def process_query(query):
35
  context = [m['metadata']['Output'] for m in xc['matches']]
36
  context_str = " ".join(context)
37
  formatted_query = f"answer the question: {query} context: {context_str}"
38
- else:
39
- # Handle the case where 'matches' isn't found or isn't in the expected format
40
- context_str = ""
41
- formatted_query = f"answer the question: {query} context: {context_str}"
42
 
43
  # Generate answer using T5 model
44
  output_text = context_str
@@ -52,4 +48,10 @@ def process_query(query):
52
  ids = generator.generate(inputs, num_beams=2, min_length=10, max_length=60, repetition_penalty=1.2)
53
  answer = tokenizer.decode(ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
54
 
 
 
 
 
 
 
55
  return answer
 
35
  context = [m['metadata']['Output'] for m in xc['matches']]
36
  context_str = " ".join(context)
37
  formatted_query = f"answer the question: {query} context: {context_str}"
 
 
 
 
38
 
39
  # Generate answer using T5 model
40
  output_text = context_str
 
48
  ids = generator.generate(inputs, num_beams=2, min_length=10, max_length=60, repetition_penalty=1.2)
49
  answer = tokenizer.decode(ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
50
 
51
+ nli_keywords = ['not_equivalent', 'not_entailment', 'entailment', 'neutral']
52
+
53
+ # If any of the keywords are found in the answer, return the fallback message
54
+ if any(keyword in answer.lower() for keyword in nli_keywords):
55
+ return "Klasmeyt, can you elaborate your question?"
56
+
57
  return answer