Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,24 @@ import gradio as gr
|
|
| 3 |
from my_memory_logic import run_with_session_memory
|
| 4 |
|
| 5 |
def chat_interface_fn(message, history, session_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
answer = run_with_session_memory(message, session_id)
|
|
|
|
|
|
|
| 7 |
history.append((message, answer))
|
|
|
|
|
|
|
| 8 |
message_dicts = []
|
| 9 |
for user_msg, ai_msg in history:
|
| 10 |
message_dicts.append({"role": "user", "content": user_msg})
|
| 11 |
message_dicts.append({"role": "assistant", "content": ai_msg})
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
my_chat_css = """
|
| 15 |
.gradio-container {
|
|
|
|
| 3 |
from my_memory_logic import run_with_session_memory
|
| 4 |
|
| 5 |
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) Call run_with_session_memory with user message and session_id
|
| 11 |
answer = run_with_session_memory(message, session_id)
|
| 12 |
+
|
| 13 |
+
# 2) Append the turn to the 'history' so Gradio UI displays it
|
| 14 |
history.append((message, answer))
|
| 15 |
+
|
| 16 |
+
# 3) Convert into message dicts for ChatInterface
|
| 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 only the list of message dictionaries
|
| 23 |
+
return message_dicts
|
| 24 |
|
| 25 |
my_chat_css = """
|
| 26 |
.gradio-container {
|