ganesh-vilje commited on
Commit
c978648
Β·
1 Parent(s): d02eed2

fix: Replace _mark_latest_pipeline_history_status with V3 functions

Browse files

- Fixed 'name _mark_latest_pipeline_history_status is not defined' error
- Replaced with _update_pipeline_status in non-streaming approval flow
- Added model attribution tracking on pipeline execution success
- Pipeline status now properly updates S3 and MongoDB metadata
- Lines 1083, 1093 updated with V3 compliance

Files changed (1) hide show
  1. api_routes_v2.py +15 -3
api_routes_v2.py CHANGED
@@ -1077,10 +1077,19 @@ async def chat_unified(
1077
  prefer_bedrock=bool(prefer_bedrock),
1078
  )
1079
  session_manager.update_session(chat_id, {"pipeline_result": result, "state": "initial"})
 
 
 
 
 
 
 
 
 
 
 
1080
  # CHANGE: include actual user-facing result
1081
  result_text = _extract_user_facing_text(result)
1082
- preview = (result_text or json.dumps(result, ensure_ascii=False))[:500]
1083
- _mark_latest_pipeline_history_status(chat_id, "executed", result_preview=preview) # CHANGE
1084
  friendly = f"πŸŽ‰ Pipeline completed successfully!\n\n{result_text or 'βœ… All done!'}" # CHANGE
1085
  api_data = {
1086
  "type": "pipeline_completed",
@@ -1090,7 +1099,10 @@ async def chat_unified(
1090
  return _assistant_response_payload(chat_id, friendly, {"intent": "pipeline_execute"}, api_data, "initial")
1091
  except Exception as e:
1092
  session_manager.update_session(chat_id, {"state": "initial"})
1093
- _mark_latest_pipeline_history_status(chat_id, "failed", result_preview=str(e)) # CHANGE
 
 
 
1094
  friendly = f"❌ Pipeline execution failed: {str(e)}"
1095
  api_data = {"type": "error", "error_code": "PIPELINE_EXECUTION_FAILED", "message": str(e)}
1096
  return _assistant_response_payload(chat_id, friendly, {"intent": "pipeline_execute"}, api_data, "initial")
 
1077
  prefer_bedrock=bool(prefer_bedrock),
1078
  )
1079
  session_manager.update_session(chat_id, {"pipeline_result": result, "state": "initial"})
1080
+ # V3: Update pipeline status in S3
1081
+ pipeline_id = proposed.get("pipeline_id")
1082
+ if pipeline_id:
1083
+ _update_pipeline_status(pipeline_id, chat_id, "completed", result=result)
1084
+ _record_model_attribution(
1085
+ pipeline_id=pipeline_id,
1086
+ session_id=chat_id,
1087
+ model_provider=proposed.get("_model_provider", "unknown"),
1088
+ model_name=proposed.get("_model", "unknown"),
1089
+ is_fallback=False
1090
+ )
1091
  # CHANGE: include actual user-facing result
1092
  result_text = _extract_user_facing_text(result)
 
 
1093
  friendly = f"πŸŽ‰ Pipeline completed successfully!\n\n{result_text or 'βœ… All done!'}" # CHANGE
1094
  api_data = {
1095
  "type": "pipeline_completed",
 
1099
  return _assistant_response_payload(chat_id, friendly, {"intent": "pipeline_execute"}, api_data, "initial")
1100
  except Exception as e:
1101
  session_manager.update_session(chat_id, {"state": "initial"})
1102
+ # V3: Update pipeline status to failed
1103
+ pipeline_id = proposed.get("pipeline_id")
1104
+ if pipeline_id:
1105
+ _update_pipeline_status(pipeline_id, chat_id, "failed", result={"error": str(e)})
1106
  friendly = f"❌ Pipeline execution failed: {str(e)}"
1107
  api_data = {"type": "error", "error_code": "PIPELINE_EXECUTION_FAILED", "message": str(e)}
1108
  return _assistant_response_payload(chat_id, friendly, {"intent": "pipeline_execute"}, api_data, "initial")