Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,11 @@ def chat_interface_fn(message, history, session_id):
|
|
| 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 |
|
|
@@ -18,7 +23,8 @@ def chat_interface_fn(message, history, session_id):
|
|
| 18 |
# 3) Convert history to message dictionaries for display
|
| 19 |
message_dicts = []
|
| 20 |
for msg in history:
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
# Return the message dicts and updated history
|
| 24 |
return message_dicts, history
|
|
|
|
| 7 |
'session_id' is used to store conversation across turns.
|
| 8 |
Deduplicates consecutive repeated Q&A pairs to avoid repetition.
|
| 9 |
"""
|
| 10 |
+
# Ensure history is a list of dictionaries
|
| 11 |
+
if history and isinstance(history[0], tuple):
|
| 12 |
+
print("DEBUG: Converting history from tuple format to dictionary format.")
|
| 13 |
+
history = [{"role": "user", "content": h[0]}, {"role": "assistant", "content": h[1]} for h in history]
|
| 14 |
+
|
| 15 |
# 1) Get answer from the session-based memory pipeline
|
| 16 |
answer = run_with_session_memory(message, session_id)
|
| 17 |
|
|
|
|
| 23 |
# 3) Convert history to message dictionaries for display
|
| 24 |
message_dicts = []
|
| 25 |
for msg in history:
|
| 26 |
+
# Ensure the message format is correct: it should always be a dictionary
|
| 27 |
+
message_dicts.append(msg)
|
| 28 |
|
| 29 |
# Return the message dicts and updated history
|
| 30 |
return message_dicts, history
|