Commit
·
9f67f77
1
Parent(s):
8204547
Revert "memory chatbot upgrade"
Browse filesThis reverts commit fa719ce6f287576c7135b09bb95b0f48bb925279.
app.py
CHANGED
|
@@ -468,23 +468,19 @@ async def stream_agent_response(question: str, chat_history: List[List[str]]) ->
|
|
| 468 |
f"3. El modelo de lenguaje esté disponible\n\n"
|
| 469 |
f"Error: {agent_error}"
|
| 470 |
)
|
| 471 |
-
return error_msg, None
|
| 472 |
|
| 473 |
# Update the agent's memory with the full conversation history
|
| 474 |
try:
|
| 475 |
-
#
|
| 476 |
if hasattr(agent, 'memory') and agent.memory is not None:
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
user_prev, bot_prev = pair[0], pair[1] if len(pair) > 1 else ""
|
| 485 |
-
agent.memory.save_context({"input": user_prev}, {"output": bot_prev})
|
| 486 |
-
except Exception:
|
| 487 |
-
continue
|
| 488 |
except Exception as e:
|
| 489 |
logger.error(f"Error updating agent memory: {str(e)}", exc_info=True)
|
| 490 |
|
|
@@ -730,7 +726,7 @@ async def stream_agent_response(question: str, chat_history: List[List[str]]) ->
|
|
| 730 |
error_msg = f"## ❌ Error\n\nOcurrió un error al procesar tu solicitud:\n\n```\n{str(e)}\n```"
|
| 731 |
logger.error(f"Error in stream_agent_response: {str(e)}", exc_info=True)
|
| 732 |
# Return error message and no chart
|
| 733 |
-
return error_msg, None
|
| 734 |
|
| 735 |
# Custom CSS for the app
|
| 736 |
custom_css = """
|
|
|
|
| 468 |
f"3. El modelo de lenguaje esté disponible\n\n"
|
| 469 |
f"Error: {agent_error}"
|
| 470 |
)
|
| 471 |
+
return error_msg, None
|
| 472 |
|
| 473 |
# Update the agent's memory with the full conversation history
|
| 474 |
try:
|
| 475 |
+
# Rebuild agent memory from chat history pairs
|
| 476 |
if hasattr(agent, 'memory') and agent.memory is not None:
|
| 477 |
+
agent.memory.clear()
|
| 478 |
+
for i in range(0, len(messages)-1, 2): # (user, assistant)
|
| 479 |
+
if i+1 < len(messages):
|
| 480 |
+
agent.memory.save_context(
|
| 481 |
+
{"input": messages[i].content},
|
| 482 |
+
{"output": messages[i+1].content}
|
| 483 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
except Exception as e:
|
| 485 |
logger.error(f"Error updating agent memory: {str(e)}", exc_info=True)
|
| 486 |
|
|
|
|
| 726 |
error_msg = f"## ❌ Error\n\nOcurrió un error al procesar tu solicitud:\n\n```\n{str(e)}\n```"
|
| 727 |
logger.error(f"Error in stream_agent_response: {str(e)}", exc_info=True)
|
| 728 |
# Return error message and no chart
|
| 729 |
+
return error_msg, None
|
| 730 |
|
| 731 |
# Custom CSS for the app
|
| 732 |
custom_css = """
|