Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,22 +23,19 @@ def format_chunks(chunks):
|
|
| 23 |
|
| 24 |
# ---------- Chat handler (tuple-based, HF compatible) ----------
|
| 25 |
def chat_handler(message, chat_history):
|
| 26 |
-
"""
|
| 27 |
-
message: str
|
| 28 |
-
chat_history: List[Tuple[user, assistant]]
|
| 29 |
-
"""
|
| 30 |
chat_history = chat_history or []
|
| 31 |
|
| 32 |
-
# Build history
|
| 33 |
history_text = ""
|
| 34 |
-
for
|
| 35 |
-
history_text += f"
|
| 36 |
|
| 37 |
# Call RAG backend
|
| 38 |
answer, chunks = answer_question(message, history_text)
|
| 39 |
|
| 40 |
-
# Append
|
| 41 |
-
chat_history.append(
|
|
|
|
| 42 |
|
| 43 |
chunk_display = format_chunks(chunks)
|
| 44 |
|
|
|
|
| 23 |
|
| 24 |
# ---------- Chat handler (tuple-based, HF compatible) ----------
|
| 25 |
def chat_handler(message, chat_history):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
chat_history = chat_history or []
|
| 27 |
|
| 28 |
+
# Build history text for RAG backend
|
| 29 |
history_text = ""
|
| 30 |
+
for msg in chat_history:
|
| 31 |
+
history_text += f"{msg['role'].capitalize()}: {msg['content']}\n"
|
| 32 |
|
| 33 |
# Call RAG backend
|
| 34 |
answer, chunks = answer_question(message, history_text)
|
| 35 |
|
| 36 |
+
# Append messages as DICTS (REQUIRED)
|
| 37 |
+
chat_history.append({"role": "user", "content": message})
|
| 38 |
+
chat_history.append({"role": "assistant", "content": answer})
|
| 39 |
|
| 40 |
chunk_display = format_chunks(chunks)
|
| 41 |
|