Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -181,23 +181,24 @@ def build_answer(query: str) -> str:
|
|
| 181 |
def chat_respond(message: str, history):
|
| 182 |
answer = build_answer(message)
|
| 183 |
|
| 184 |
-
#
|
| 185 |
-
|
| 186 |
|
| 187 |
if isinstance(history, list):
|
| 188 |
-
for
|
| 189 |
-
if isinstance(
|
| 190 |
-
|
| 191 |
-
elif isinstance(
|
| 192 |
-
|
| 193 |
-
|
| 194 |
|
| 195 |
# Append new messages
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
# ChatInterface expects just the answer, NOT a tuple for the reply
|
| 200 |
-
return answer, cleaned_history
|
| 201 |
|
| 202 |
|
| 203 |
# -----------------------------
|
|
|
|
| 181 |
def chat_respond(message: str, history):
|
| 182 |
answer = build_answer(message)
|
| 183 |
|
| 184 |
+
# Normalize history into the format ChatInterface expects
|
| 185 |
+
normalized = []
|
| 186 |
|
| 187 |
if isinstance(history, list):
|
| 188 |
+
for item in history:
|
| 189 |
+
if isinstance(item, dict):
|
| 190 |
+
normalized.append(item)
|
| 191 |
+
elif isinstance(item, tuple) and len(item) == 2:
|
| 192 |
+
normalized.append({"role": "user", "content": item[0]})
|
| 193 |
+
normalized.append({"role": "assistant", "content": item[1]})
|
| 194 |
|
| 195 |
# Append new messages
|
| 196 |
+
normalized.append({"role": "user", "content": message})
|
| 197 |
+
normalized.append({"role": "assistant", "content": answer})
|
| 198 |
+
|
| 199 |
+
# MUST return: (string_answer, list_of_dict_messages)
|
| 200 |
+
return answer, normalized
|
| 201 |
|
|
|
|
|
|
|
| 202 |
|
| 203 |
|
| 204 |
# -----------------------------
|