Jeremy Live commited on
Commit
86da53d
·
1 Parent(s): 6aebc39

fixed the message format issue

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -570,15 +570,21 @@ async def stream_agent_response(question: str, chat_history: List) -> List[Dict]
570
  assistant_message["content"] = f"## ❌ Error\n\n{error_msg}"
571
 
572
  # Return the message in the correct format for Gradio Chatbot
573
- # Format: [(user_message, assistant_message), ...]
574
- # Ensure we're returning a list of tuples where each tuple is (user_msg, bot_msg)
 
 
575
  if isinstance(assistant_message, dict) and "content" in assistant_message:
576
- return [(None, assistant_message["content"])]
577
  elif isinstance(assistant_message, str):
578
- return [(None, assistant_message)]
579
  else:
580
- # Fallback: convert to string representation
581
- return [(None, str(assistant_message))]
 
 
 
 
582
 
583
  except Exception as e:
584
  error_msg = f"## ❌ Error\n\nOcurrió un error al procesar tu solicitud:\n\n```\n{str(e)}\n```"
 
570
  assistant_message["content"] = f"## ❌ Error\n\n{error_msg}"
571
 
572
  # Return the message in the correct format for Gradio Chatbot
573
+ # Format: list of tuples where each tuple is (user_msg, bot_msg)
574
+ # For a single response, we return [(None, message)]
575
+ message_content = ""
576
+
577
  if isinstance(assistant_message, dict) and "content" in assistant_message:
578
+ message_content = assistant_message["content"]
579
  elif isinstance(assistant_message, str):
580
+ message_content = assistant_message
581
  else:
582
+ message_content = str(assistant_message)
583
+
584
+ # Ensure we return a list of tuples in the format Gradio expects
585
+ # Each message should be a tuple of (user_msg, bot_msg)
586
+ # For assistant messages, user_msg is None
587
+ return [(None, message_content)]
588
 
589
  except Exception as e:
590
  error_msg = f"## ❌ Error\n\nOcurrió un error al procesar tu solicitud:\n\n```\n{str(e)}\n```"