TO REMOVE CHAT HISTORY(SHOWN) IN CHAT
Browse files
app.py
CHANGED
|
@@ -6,21 +6,23 @@ def chat_interface_fn(message, history, session_id):
|
|
| 6 |
"""
|
| 7 |
Multi-turn chat function for Gradio's ChatInterface.
|
| 8 |
'session_id' is used to store conversation across turns.
|
|
|
|
| 9 |
"""
|
| 10 |
-
# 1)
|
| 11 |
answer = run_with_session_memory(message, session_id)
|
| 12 |
|
| 13 |
-
# 2)
|
| 14 |
-
history
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
message_dicts = []
|
| 18 |
for user_msg, ai_msg in history:
|
| 19 |
message_dicts.append({"role": "user", "content": user_msg})
|
| 20 |
message_dicts.append({"role": "assistant", "content": ai_msg})
|
| 21 |
|
| 22 |
-
# Return
|
| 23 |
-
return message_dicts
|
| 24 |
|
| 25 |
my_chat_css = """
|
| 26 |
.gradio-container {
|
|
@@ -45,3 +47,4 @@ with gr.Blocks(css=my_chat_css) as demo:
|
|
| 45 |
)
|
| 46 |
|
| 47 |
demo.launch()
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
Multi-turn chat function for Gradio's ChatInterface.
|
| 8 |
'session_id' is used to store conversation across turns.
|
| 9 |
+
Deduplicates consecutive repeated Q&A pairs to avoid repetition.
|
| 10 |
"""
|
| 11 |
+
# 1) Get answer from the session-based memory pipeline
|
| 12 |
answer = run_with_session_memory(message, session_id)
|
| 13 |
|
| 14 |
+
# 2) Deduplicate consecutive identical exchanges
|
| 15 |
+
if not history or history[-1] != (message, answer):
|
| 16 |
+
history.append((message, answer))
|
| 17 |
+
|
| 18 |
+
# 3) Convert history to message dictionaries for display
|
| 19 |
message_dicts = []
|
| 20 |
for user_msg, ai_msg in history:
|
| 21 |
message_dicts.append({"role": "user", "content": user_msg})
|
| 22 |
message_dicts.append({"role": "assistant", "content": ai_msg})
|
| 23 |
|
| 24 |
+
# Return the message dicts and updated history
|
| 25 |
+
return message_dicts, history
|
| 26 |
|
| 27 |
my_chat_css = """
|
| 28 |
.gradio-container {
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
demo.launch()
|
| 50 |
+
|