peterpull commited on
Commit
9139588
·
1 Parent(s): 46add35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -64,16 +64,23 @@ def get_index(index_file_path):
64
  sys.exit()
65
 
66
  # passes the prompt to the chatbot
67
- def chatbot(input_text, mentioned_person='Mediator John Haynes'):
68
  index = get_index(INDEX_FILE)
69
  prompt = f"You are {mentioned_person}: {input_text}\n\n At the end of your answer ask a provocative question."
70
- response = index.query(prompt, response_mode="compact")
71
 
72
- store_message(input_text,response)
73
- print(f"Chat input: {input_text}\nChatbot response: {response.response}")
 
 
 
 
 
 
74
 
75
  # return the response
76
- return response.response
 
77
 
78
 
79
  iface = Interface(
 
64
  sys.exit()
65
 
66
  # passes the prompt to the chatbot
67
+ def chatbot(input_text, mentioned_person='Mediator John Haynes', confidence_threshold=0.5):
68
  index = get_index(INDEX_FILE)
69
  prompt = f"You are {mentioned_person}: {input_text}\n\n At the end of your answer ask a provocative question."
70
+ response = index.query(prompt, response_mode="detailed")[0]
71
 
72
+ # Check the confidence score of the response
73
+ if response.score < confidence_threshold:
74
+ response_text = "I'm not sure how to respond to that."
75
+ else:
76
+ response_text = response.response
77
+
78
+ store_message(input_text, response_text)
79
+ print(f"Chat input: {input_text}\nChatbot response: {response_text}")
80
 
81
  # return the response
82
+ return response_text
83
+
84
 
85
 
86
  iface = Interface(