Spaces:
Sleeping
Sleeping
Commit
Β·
d8b9e43
1
Parent(s):
7eea49e
Update api_routes_v2.py
Browse files- api_routes_v2.py +11 -36
api_routes_v2.py
CHANGED
|
@@ -749,7 +749,8 @@ def _assistant_response_payload(
|
|
| 749 |
output: Optional[Dict[str, Any]] = None,
|
| 750 |
final_output: Optional[Dict[str, Any]] = None,
|
| 751 |
exception: Optional[str] = None,
|
| 752 |
-
pipeline_result: Optional[Dict[str, Any]] = None
|
|
|
|
| 753 |
) -> ChatResponse:
|
| 754 |
"""
|
| 755 |
Create ChatResponse payload with all required fields.
|
|
@@ -758,12 +759,13 @@ def _assistant_response_payload(
|
|
| 758 |
from services.schemas import generate_message_id
|
| 759 |
message_id = generate_message_id()
|
| 760 |
|
| 761 |
-
# Persist assistant message to S3 WITH pipeline results
|
| 762 |
_add_and_mirror_message(
|
| 763 |
chat_id=chat_id,
|
| 764 |
role="assistant",
|
| 765 |
content=friendly_response,
|
| 766 |
-
pipeline_result=pipeline_result #
|
|
|
|
| 767 |
)
|
| 768 |
|
| 769 |
# Get file metadata from session
|
|
@@ -1450,16 +1452,6 @@ async def chat_unified(
|
|
| 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,
|
|
@@ -1514,7 +1506,8 @@ async def chat_unified(
|
|
| 1514 |
output=output,
|
| 1515 |
final_output=final_output,
|
| 1516 |
exception=exception_msg,
|
| 1517 |
-
pipeline_result=result # NEW: Pass the pipeline results
|
|
|
|
| 1518 |
)
|
| 1519 |
else:
|
| 1520 |
# Pipeline failed or partially completed
|
|
@@ -1536,16 +1529,6 @@ async def chat_unified(
|
|
| 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,
|
|
@@ -1573,7 +1556,8 @@ async def chat_unified(
|
|
| 1573 |
output=output,
|
| 1574 |
final_output=final_output,
|
| 1575 |
exception=exception_msg,
|
| 1576 |
-
pipeline_result=result # NEW: Pass results even for failures
|
|
|
|
| 1577 |
)
|
| 1578 |
except Exception as e:
|
| 1579 |
session_manager.update_session(chat_id, {"state": "initial"})
|
|
@@ -1609,16 +1593,6 @@ async def chat_unified(
|
|
| 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",
|
|
@@ -1641,7 +1615,8 @@ async def chat_unified(
|
|
| 1641 |
api_data=api_data,
|
| 1642 |
state="initial",
|
| 1643 |
exception=str(e),
|
| 1644 |
-
pipeline_result=error_result # NEW: Include error in pipeline_result
|
|
|
|
| 1645 |
)
|
| 1646 |
finally:
|
| 1647 |
try:
|
|
|
|
| 749 |
output: Optional[Dict[str, Any]] = None,
|
| 750 |
final_output: Optional[Dict[str, Any]] = None,
|
| 751 |
exception: Optional[str] = None,
|
| 752 |
+
pipeline_result: Optional[Dict[str, Any]] = None,
|
| 753 |
+
pipeline_id: Optional[str] = None, # β
ADD THIS PARAMETER
|
| 754 |
) -> ChatResponse:
|
| 755 |
"""
|
| 756 |
Create ChatResponse payload with all required fields.
|
|
|
|
| 759 |
from services.schemas import generate_message_id
|
| 760 |
message_id = generate_message_id()
|
| 761 |
|
| 762 |
+
# Persist assistant message to S3 WITH pipeline results AND pipeline_id
|
| 763 |
_add_and_mirror_message(
|
| 764 |
chat_id=chat_id,
|
| 765 |
role="assistant",
|
| 766 |
content=friendly_response,
|
| 767 |
+
pipeline_result=pipeline_result, # Pass pipeline results
|
| 768 |
+
pipeline_id=pipeline_id # β
PASS THE PIPELINE_ID HERE
|
| 769 |
)
|
| 770 |
|
| 771 |
# Get file metadata from session
|
|
|
|
| 1452 |
if is_success:
|
| 1453 |
friendly = "π Pipeline completed successfully!"
|
| 1454 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1455 |
output = {
|
| 1456 |
"component_summary": "Pipeline executed successfully",
|
| 1457 |
"steps": total_steps,
|
|
|
|
| 1506 |
output=output,
|
| 1507 |
final_output=final_output,
|
| 1508 |
exception=exception_msg,
|
| 1509 |
+
pipeline_result=result, # NEW: Pass the pipeline results
|
| 1510 |
+
pipeline_id=pipeline_id # β
PASS pipeline_id HERE
|
| 1511 |
)
|
| 1512 |
else:
|
| 1513 |
# Pipeline failed or partially completed
|
|
|
|
| 1529 |
else:
|
| 1530 |
friendly = f"β οΈ Pipeline partially completed: {error_msg}"
|
| 1531 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1532 |
output = {
|
| 1533 |
"component_summary": f"Pipeline {pipeline_status}",
|
| 1534 |
"steps": total_steps,
|
|
|
|
| 1556 |
output=output,
|
| 1557 |
final_output=final_output,
|
| 1558 |
exception=exception_msg,
|
| 1559 |
+
pipeline_result=result, # NEW: Pass results even for failures
|
| 1560 |
+
pipeline_id=pipeline_id # β
PASS pipeline_id HERE
|
| 1561 |
)
|
| 1562 |
except Exception as e:
|
| 1563 |
session_manager.update_session(chat_id, {"state": "initial"})
|
|
|
|
| 1593 |
"error": str(e)
|
| 1594 |
}
|
| 1595 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1596 |
api_data = {
|
| 1597 |
"type": "error",
|
| 1598 |
"error_code": "PIPELINE_EXECUTION_FAILED",
|
|
|
|
| 1615 |
api_data=api_data,
|
| 1616 |
state="initial",
|
| 1617 |
exception=str(e),
|
| 1618 |
+
pipeline_result=error_result, # NEW: Include error in pipeline_result
|
| 1619 |
+
pipeline_id=pipeline_id # β
PASS pipeline_id HERE
|
| 1620 |
)
|
| 1621 |
finally:
|
| 1622 |
try:
|