Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,22 @@ from my_memory_logic import run_with_session_memory
|
|
3 |
|
4 |
def chat_interface_fn(message, history, session_id):
|
5 |
"""
|
6 |
-
|
7 |
-
|
|
|
8 |
"""
|
9 |
# 1) Get answer from the session-based memory pipeline
|
10 |
answer = run_with_session_memory(message, session_id)
|
11 |
|
12 |
-
# 2)
|
13 |
-
history
|
|
|
|
|
14 |
|
15 |
-
# 3) Convert
|
16 |
message_dicts = []
|
17 |
-
for
|
18 |
-
message_dicts.append(
|
19 |
-
message_dicts.append({"role": "assistant", "content": ai_msg})
|
20 |
|
21 |
# Return the message dicts and updated history
|
22 |
return message_dicts, history
|
|
|
3 |
|
4 |
def chat_interface_fn(message, history, session_id):
|
5 |
"""
|
6 |
+
Multi-turn chat function for Gradio's ChatInterface.
|
7 |
+
'session_id' is used to store conversation across turns.
|
8 |
+
Deduplicates consecutive repeated Q&A pairs to avoid repetition.
|
9 |
"""
|
10 |
# 1) Get answer from the session-based memory pipeline
|
11 |
answer = run_with_session_memory(message, session_id)
|
12 |
|
13 |
+
# 2) Deduplicate consecutive identical exchanges
|
14 |
+
if not history or history[-1]["content"] != answer:
|
15 |
+
history.append({"role": "user", "content": message})
|
16 |
+
history.append({"role": "assistant", "content": answer})
|
17 |
|
18 |
+
# 3) Convert history to message dictionaries for display
|
19 |
message_dicts = []
|
20 |
+
for msg in history:
|
21 |
+
message_dicts.append(msg) # Directly append the dictionary
|
|
|
22 |
|
23 |
# Return the message dicts and updated history
|
24 |
return message_dicts, history
|