Spaces:
Sleeping
Sleeping
Commit
Β·
7eea49e
1
Parent(s):
fc7cdd2
Update api_routes_v2.py
Browse files- api_routes_v2.py +46 -5
api_routes_v2.py
CHANGED
|
@@ -640,11 +640,14 @@ def _build_api_result_summary(result: Dict[str, Any], session: Dict[str, Any]) -
|
|
| 640 |
return {"summary": summary, "metadata": metadata}
|
| 641 |
|
| 642 |
def _add_and_mirror_message(
|
| 643 |
-
chat_id: str,
|
| 644 |
-
role: str,
|
| 645 |
-
content: str,
|
| 646 |
-
|
| 647 |
-
|
|
|
|
|
|
|
|
|
|
| 648 |
):
|
| 649 |
"""
|
| 650 |
V3 RULE: Append message to S3 conversation.
|
|
@@ -1446,6 +1449,17 @@ async def chat_unified(
|
|
| 1446 |
# Build response based on actual success/failure
|
| 1447 |
if is_success:
|
| 1448 |
friendly = "π Pipeline completed successfully!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1449 |
output = {
|
| 1450 |
"component_summary": "Pipeline executed successfully",
|
| 1451 |
"steps": total_steps,
|
|
@@ -1522,6 +1536,16 @@ async def chat_unified(
|
|
| 1522 |
else:
|
| 1523 |
friendly = f"β οΈ Pipeline partially completed: {error_msg}"
|
| 1524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1525 |
output = {
|
| 1526 |
"component_summary": f"Pipeline {pipeline_status}",
|
| 1527 |
"steps": total_steps,
|
|
@@ -1578,6 +1602,23 @@ async def chat_unified(
|
|
| 1578 |
print(f"Warning: Could not get component error details: {comp_error}")
|
| 1579 |
|
| 1580 |
friendly = f"β Pipeline execution failed: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1581 |
api_data = {
|
| 1582 |
"type": "error",
|
| 1583 |
"error_code": "PIPELINE_EXECUTION_FAILED",
|
|
|
|
| 640 |
return {"summary": summary, "metadata": metadata}
|
| 641 |
|
| 642 |
def _add_and_mirror_message(
|
| 643 |
+
chat_id: str,
|
| 644 |
+
role: str,
|
| 645 |
+
content: str,
|
| 646 |
+
*,
|
| 647 |
+
pipeline_id: Optional[str] = None,
|
| 648 |
+
pipeline_status: Optional[str] = None,
|
| 649 |
+
pipeline_result: Optional[dict] = None,
|
| 650 |
+
file_metadata: Optional[dict] = None,
|
| 651 |
):
|
| 652 |
"""
|
| 653 |
V3 RULE: Append message to S3 conversation.
|
|
|
|
| 1449 |
# Build response based on actual success/failure
|
| 1450 |
if is_success:
|
| 1451 |
friendly = "π Pipeline completed successfully!"
|
| 1452 |
+
|
| 1453 |
+
# β
NEW: persist assistant message with pipeline result
|
| 1454 |
+
_add_and_mirror_message(
|
| 1455 |
+
chat_id,
|
| 1456 |
+
"assistant",
|
| 1457 |
+
friendly,
|
| 1458 |
+
pipeline_id=pipeline_id,
|
| 1459 |
+
pipeline_status="completed",
|
| 1460 |
+
pipeline_result=result
|
| 1461 |
+
)
|
| 1462 |
+
|
| 1463 |
output = {
|
| 1464 |
"component_summary": "Pipeline executed successfully",
|
| 1465 |
"steps": total_steps,
|
|
|
|
| 1536 |
else:
|
| 1537 |
friendly = f"β οΈ Pipeline partially completed: {error_msg}"
|
| 1538 |
|
| 1539 |
+
# β
NEW: persist failure result
|
| 1540 |
+
_add_and_mirror_message(
|
| 1541 |
+
chat_id,
|
| 1542 |
+
"assistant",
|
| 1543 |
+
friendly,
|
| 1544 |
+
pipeline_id=pipeline_id,
|
| 1545 |
+
pipeline_status=pipeline_status,
|
| 1546 |
+
pipeline_result=result
|
| 1547 |
+
)
|
| 1548 |
+
|
| 1549 |
output = {
|
| 1550 |
"component_summary": f"Pipeline {pipeline_status}",
|
| 1551 |
"steps": total_steps,
|
|
|
|
| 1602 |
print(f"Warning: Could not get component error details: {comp_error}")
|
| 1603 |
|
| 1604 |
friendly = f"β Pipeline execution failed: {str(e)}"
|
| 1605 |
+
|
| 1606 |
+
error_result = {
|
| 1607 |
+
"pipeline_id": pipeline_id,
|
| 1608 |
+
"status": "failed",
|
| 1609 |
+
"error": str(e)
|
| 1610 |
+
}
|
| 1611 |
+
|
| 1612 |
+
# β
NEW: persist exception result
|
| 1613 |
+
_add_and_mirror_message(
|
| 1614 |
+
chat_id,
|
| 1615 |
+
"assistant",
|
| 1616 |
+
friendly,
|
| 1617 |
+
pipeline_id=pipeline_id,
|
| 1618 |
+
pipeline_status="failed",
|
| 1619 |
+
pipeline_result=error_result
|
| 1620 |
+
)
|
| 1621 |
+
|
| 1622 |
api_data = {
|
| 1623 |
"type": "error",
|
| 1624 |
"error_code": "PIPELINE_EXECUTION_FAILED",
|