sofzcc commited on
Commit
b68432d
·
verified ·
1 Parent(s): c087585

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
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
- # Convert Gradio history (list of dicts) OR tuples into safe message list
185
- cleaned_history = []
186
 
187
  if isinstance(history, list):
188
- for m in history:
189
- if isinstance(m, dict): # already the new format
190
- cleaned_history.append(m)
191
- elif isinstance(m, tuple) and len(m) == 2:
192
- cleaned_history.append({"role": "user", "content": m[0]})
193
- cleaned_history.append({"role": "assistant", "content": m[1]})
194
 
195
  # Append new messages
196
- cleaned_history.append({"role": "user", "content": message})
197
- cleaned_history.append({"role": "assistant", "content": answer})
 
 
 
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
  # -----------------------------