Update app.py
Browse files
app.py
CHANGED
@@ -21,13 +21,23 @@ def chat_history_fn(user_input, history):
|
|
21 |
memory.chat_memory.add_user_message(user_input)
|
22 |
memory.chat_memory.add_ai_message(answer)
|
23 |
|
24 |
-
# 4)
|
|
|
25 |
history.append((user_input, answer))
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
demo = gr.ChatInterface(
|
29 |
fn=chat_history_fn,
|
30 |
title="DailyWellnessAI with Memory",
|
31 |
description="A chat bot that remembers context using memory + question restatement."
|
32 |
)
|
33 |
-
|
|
|
|
|
|
21 |
memory.chat_memory.add_user_message(user_input)
|
22 |
memory.chat_memory.add_ai_message(answer)
|
23 |
|
24 |
+
# 4) Convert the updated history to a list of message dicts.
|
25 |
+
# This is what Gradio's ChatInterface expects (instead of returning a tuple).
|
26 |
history.append((user_input, answer))
|
27 |
+
message_dicts = []
|
28 |
+
for user_msg, ai_msg in history:
|
29 |
+
# user turn
|
30 |
+
message_dicts.append({"role": "user", "content": user_msg})
|
31 |
+
# AI turn
|
32 |
+
message_dicts.append({"role": "assistant", "content": ai_msg})
|
33 |
+
|
34 |
+
return message_dicts
|
35 |
|
36 |
demo = gr.ChatInterface(
|
37 |
fn=chat_history_fn,
|
38 |
title="DailyWellnessAI with Memory",
|
39 |
description="A chat bot that remembers context using memory + question restatement."
|
40 |
)
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
demo.launch()
|