Jeremy Live commited on
Commit
2b004c4
·
1 Parent(s): 47347d6

Revert "scnd graph v2"

Browse files

This reverts commit 89a7ec71b4c537ee83be47207052a1f5d75e6fee.

Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -542,28 +542,29 @@ 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
- # Add empty assistant message that will be updated
546
- assistant_message = {"role": "assistant", "content": ""}
547
- messages.append(assistant_message)
548
-
549
- # Execute the agent with proper error handling
550
- try:
551
- # If the user is asking for a chart, steer the agent to be concise
552
- wants_chart, _desired = detect_chart_preferences(question)
553
- input_text = question
554
- if wants_chart:
555
- input_text = (
556
- "Instrucciones: Si el usuario pide una visualización y los datos ya "
557
- "están en el historial, no pidas más contexto. Responde brevemente "
558
- "confirmando que generarás/has generado la gráfica y, si necesitas SQL, "
559
- "devuelve solo la consulta en un bloque ```sql``` sin explicaciones.\n\n"
560
- f"Pregunta del usuario: {question}"
561
- )
 
562
 
563
- # Let the agent use its memory; don't pass raw chat_history
564
- response = await agent.ainvoke({"input": input_text})
565
- logger.info(f"Agent response type: {type(response)}")
566
- logger.info(f"Agent response content: {str(response)[:500]}...")
567
 
568
  # Handle different response formats
569
  if hasattr(response, 'output') and response.output:
 
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
+ # If the user is asking for a chart, steer the agent to be concise
553
+ wants_chart, _desired = detect_chart_preferences(question)
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
 
569
  # Handle different response formats
570
  if hasattr(response, 'output') and response.output: