Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -513,30 +513,25 @@ print("=" * 50)
|
|
| 513 |
# -----------------------------
|
| 514 |
|
| 515 |
def rag_respond(message, history):
|
| 516 |
-
"""Handle chat messages for chatbot UI (messages format)"""
|
| 517 |
if history is None:
|
| 518 |
history = []
|
| 519 |
|
| 520 |
-
if not message or not str(message).strip():
|
| 521 |
-
return "", history
|
| 522 |
-
|
| 523 |
user_msg = str(message)
|
| 524 |
|
| 525 |
-
history
|
| 526 |
-
|
| 527 |
-
"content": user_msg,
|
| 528 |
-
})
|
| 529 |
|
|
|
|
| 530 |
bot_reply = rag_index.answer(user_msg)
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
"content": bot_reply,
|
| 535 |
-
})
|
| 536 |
|
|
|
|
| 537 |
return "", history
|
| 538 |
|
| 539 |
|
|
|
|
| 540 |
def upload_to_kb(files):
|
| 541 |
"""Save uploaded files into the KB directory"""
|
| 542 |
if not files:
|
|
|
|
| 513 |
# -----------------------------
|
| 514 |
|
| 515 |
def rag_respond(message, history):
|
|
|
|
| 516 |
if history is None:
|
| 517 |
history = []
|
| 518 |
|
|
|
|
|
|
|
|
|
|
| 519 |
user_msg = str(message)
|
| 520 |
|
| 521 |
+
# Append to UI history ONLY
|
| 522 |
+
history.append({"role": "user", "content": user_msg})
|
|
|
|
|
|
|
| 523 |
|
| 524 |
+
# ❗ Do NOT pass history to rag_index.answer()
|
| 525 |
bot_reply = rag_index.answer(user_msg)
|
| 526 |
|
| 527 |
+
# Append assistant reply for UI display
|
| 528 |
+
history.append({"role": "assistant", "content": bot_reply})
|
|
|
|
|
|
|
| 529 |
|
| 530 |
+
# Return blank input + updated UI history
|
| 531 |
return "", history
|
| 532 |
|
| 533 |
|
| 534 |
+
|
| 535 |
def upload_to_kb(files):
|
| 536 |
"""Save uploaded files into the KB directory"""
|
| 537 |
if not files:
|