sofzcc commited on
Commit
d180139
·
verified ·
1 Parent(s): a7b58e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -178,11 +178,26 @@ def build_answer(query: str) -> str:
178
  return intro + "\n".join(bullets) + guidance
179
 
180
 
181
- def chat_respond(message: str, history: List[Tuple[str, str]]):
182
- """Gradio ChatInterface-compatible respond function."""
183
  answer = build_answer(message)
184
- history = history + [(message, answer)]
185
- return answer, history
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
 
188
  # -----------------------------
@@ -201,7 +216,7 @@ chat = gr.ChatInterface(
201
  fn=chat_respond,
202
  title="Self-Service KB Assistant",
203
  description=description,
204
- chatbot=gr.Chatbot(height=420, show_copy_button=True),
205
  examples=[
206
  "What makes a good knowledge base article?",
207
  "How could a KB assistant help agents?",
 
178
  return intro + "\n".join(bullets) + guidance
179
 
180
 
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
  # -----------------------------
 
216
  fn=chat_respond,
217
  title="Self-Service KB Assistant",
218
  description=description,
219
+ chatbot=gr.Chatbot(height=420, show_copy_button=True, type="messages"),
220
  examples=[
221
  "What makes a good knowledge base article?",
222
  "How could a KB assistant help agents?",