Jeremy Live
commited on
Commit
路
9072687
1
Parent(s):
2b004c4
Revert "UX de respuesta text segunda grafica"
Browse filesThis reverts commit ccbfee5cf368fac7707f0374bb803451dcccafa9.
app.py
CHANGED
@@ -542,27 +542,15 @@ async def stream_agent_response(question: str, chat_history: List[List[str]]) ->
|
|
542 |
except Exception as e:
|
543 |
logger.error(f"Error updating agent memory: {str(e)}", exc_info=True)
|
544 |
|
545 |
-
|
546 |
# Add empty assistant message that will be updated
|
547 |
assistant_message = {"role": "assistant", "content": ""}
|
548 |
messages.append(assistant_message)
|
549 |
|
550 |
# Execute the agent with proper error handling
|
551 |
try:
|
552 |
-
|
553 |
-
|
554 |
-
input_text = question
|
555 |
-
if wants_chart:
|
556 |
-
input_text = (
|
557 |
-
"Instrucciones: Si el usuario pide una visualizaci贸n y los datos ya "
|
558 |
-
"est谩n en el historial, no pidas m谩s contexto. Responde brevemente "
|
559 |
-
"confirmando que generar谩s/has generado la gr谩fica y, si necesitas SQL, "
|
560 |
-
"devuelve solo la consulta en un bloque ```sql``` sin explicaciones.\n\n"
|
561 |
-
f"Pregunta del usuario: {question}"
|
562 |
-
)
|
563 |
-
|
564 |
-
# Let the agent use its memory; don't pass raw chat_history
|
565 |
-
response = await agent.ainvoke({"input": input_text})
|
566 |
logger.info(f"Agent response type: {type(response)}")
|
567 |
logger.info(f"Agent response content: {str(response)[:500]}...")
|
568 |
|
@@ -769,27 +757,6 @@ async def stream_agent_response(question: str, chat_history: List[List[str]]) ->
|
|
769 |
else:
|
770 |
message_content = str(assistant_message)
|
771 |
|
772 |
-
# If we generated a chart but the model said it couldn't, replace with a friendly note
|
773 |
-
def looks_unhelpful(msg: str) -> bool:
|
774 |
-
if not isinstance(msg, str):
|
775 |
-
return False
|
776 |
-
patterns = [
|
777 |
-
r"no t(engo|iene) suficiente informaci贸n",
|
778 |
-
r"i don'?t have enough information",
|
779 |
-
r"need to know what data",
|
780 |
-
r"can you provide more context",
|
781 |
-
r"not enough info",
|
782 |
-
]
|
783 |
-
text = msg.lower()
|
784 |
-
return any(re.search(p, text) for p in patterns)
|
785 |
-
|
786 |
-
if chart_fig is not None and looks_unhelpful(message_content):
|
787 |
-
message_content = (
|
788 |
-
"He generado la gr谩fica solicitada utilizando los datos m谩s "
|
789 |
-
"recientes de la conversaci贸n. La visualizaci贸n interactiva se "
|
790 |
-
"muestra abajo."
|
791 |
-
)
|
792 |
-
|
793 |
# Return the assistant's response and an optional interactive chart figure
|
794 |
if chart_fig is None:
|
795 |
logger.info("No chart generated for this turn.")
|
|
|
542 |
except Exception as e:
|
543 |
logger.error(f"Error updating agent memory: {str(e)}", exc_info=True)
|
544 |
|
545 |
+
try:
|
546 |
# Add empty assistant message that will be updated
|
547 |
assistant_message = {"role": "assistant", "content": ""}
|
548 |
messages.append(assistant_message)
|
549 |
|
550 |
# Execute the agent with proper error handling
|
551 |
try:
|
552 |
+
# Let the agent use its memory; don't pass raw chat_history
|
553 |
+
response = await agent.ainvoke({"input": question})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
logger.info(f"Agent response type: {type(response)}")
|
555 |
logger.info(f"Agent response content: {str(response)[:500]}...")
|
556 |
|
|
|
757 |
else:
|
758 |
message_content = str(assistant_message)
|
759 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
760 |
# Return the assistant's response and an optional interactive chart figure
|
761 |
if chart_fig is None:
|
762 |
logger.info("No chart generated for this turn.")
|