Reality123b commited on
Commit
6ac5501
·
verified ·
1 Parent(s): f10933d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -33,11 +33,24 @@ class XylariaChat:
33
 
34
  def reset_conversation(self):
35
  """
36
- Completely reset the conversation history and persistent memory
37
- This helps prevent exposing previous users' conversations
38
  """
 
39
  self.conversation_history = []
40
- self.persistent_memory = {}
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  def get_response(self, user_input):
43
  # Prepare messages with conversation context and persistent memory
@@ -173,15 +186,9 @@ class XylariaChat:
173
  outputs=[chatbot],
174
  queue=False
175
  )
176
-
177
- # Add event listener to clear memory when browser tab is closed
178
- demo.js("""
179
- () => {
180
- window.addEventListener('beforeunload', function() {
181
- window.localStorage.clear();
182
- });
183
- }
184
- """)
185
 
186
  return demo
187
 
 
33
 
34
  def reset_conversation(self):
35
  """
36
+ Completely reset the conversation history, persistent memory,
37
+ and clear API-side memory
38
  """
39
+ # Clear local memory
40
  self.conversation_history = []
41
+ self.persistent_memory.clear()
42
+
43
+ # Clear API-side memory by resetting the conversation
44
+ try:
45
+ # Attempt to clear any API-side session or context
46
+ self.client = InferenceClient(
47
+ model="Qwen/QwQ-32B-Preview",
48
+ api_key=self.hf_token
49
+ )
50
+ except Exception as e:
51
+ print(f"Error resetting API client: {e}")
52
+
53
+ return None # To clear the chatbot interface
54
 
55
  def get_response(self, user_input):
56
  # Prepare messages with conversation context and persistent memory
 
186
  outputs=[chatbot],
187
  queue=False
188
  )
189
+
190
+ # Ensure memory is cleared when the interface is closed
191
+ demo.load(self.reset_conversation, None, None)
 
 
 
 
 
 
192
 
193
  return demo
194