rodrisouza commited on
Commit
db2a716
·
verified ·
1 Parent(s): 0466197

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -73,12 +73,6 @@ chat_history = []
73
  def interact(user_input, history, interaction_count):
74
  global tokenizer, model
75
  try:
76
- if interaction_count >= MAX_INTERACTIONS:
77
- response = "Thank you for your questions. Our session is now over. Goodbye!"
78
- history.append({"role": "assistant", "content": response})
79
- formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
80
- return "", formatted_history, history, interaction_count
81
-
82
  if tokenizer is None or model is None:
83
  raise ValueError("Tokenizer or model is not initialized.")
84
 
@@ -102,6 +96,10 @@ def interact(user_input, history, interaction_count):
102
  history.append({"role": "user", "content": user_input})
103
  history.append({"role": "assistant", "content": response})
104
 
 
 
 
 
105
  formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
106
 
107
  return "", formatted_history, history, interaction_count
 
73
  def interact(user_input, history, interaction_count):
74
  global tokenizer, model
75
  try:
 
 
 
 
 
 
76
  if tokenizer is None or model is None:
77
  raise ValueError("Tokenizer or model is not initialized.")
78
 
 
96
  history.append({"role": "user", "content": user_input})
97
  history.append({"role": "assistant", "content": response})
98
 
99
+ if interaction_count >= MAX_INTERACTIONS:
100
+ response += "\n\nThank you for your questions. Our session is now over. Goodbye!"
101
+ history[-1]["content"] = response
102
+
103
  formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
104
 
105
  return "", formatted_history, history, interaction_count