Jeremy Live commited on
Commit
6aebc39
·
1 Parent(s): 8c64153

fixed the message format issue

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -828,17 +828,18 @@ def create_application():
828
  # Call the agent and get the response
829
  response = await stream_agent_response(question, chat_history[:-2])
830
 
831
- if isinstance(response, list):
832
- for msg in response:
833
- if msg["role"] == "assistant":
834
- # Update the assistant's response
835
- chat_history[-1] = msg
 
836
 
837
  logger.info("Response generation complete")
838
  return chat_history
839
 
840
  except Exception as e:
841
- error_msg = f"Error al procesar la solicitud: {str(e)}"
842
  logger.error(error_msg, exc_info=True)
843
  chat_history[-1]["content"] = error_msg
844
  return chat_history
 
828
  # Call the agent and get the response
829
  response = await stream_agent_response(question, chat_history[:-2])
830
 
831
+ # Convert the response to the correct format for the chat history
832
+ if isinstance(response, list) and response:
833
+ # The response is already in the format [(None, assistant_message)]
834
+ # Extract the assistant message and update the chat history
835
+ assistant_message = response[0][1] if isinstance(response[0], (list, tuple)) and len(response[0]) > 1 else str(response[0])
836
+ chat_history[-1]["content"] = assistant_message
837
 
838
  logger.info("Response generation complete")
839
  return chat_history
840
 
841
  except Exception as e:
842
+ error_msg = f"## ❌ Error\n\nError al procesar la solicitud:\n\n```\n{str(e)}\n```"
843
  logger.error(error_msg, exc_info=True)
844
  chat_history[-1]["content"] = error_msg
845
  return chat_history