workflow_run.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from flask_restful import Resource, marshal_with, reqparse
  2. from flask_restful.inputs import int_range
  3. from controllers.console import api
  4. from controllers.console.app.wraps import get_app_model
  5. from controllers.console.setup import setup_required
  6. from controllers.console.wraps import account_initialization_required
  7. from fields.workflow_run_fields import (
  8. advanced_chat_workflow_run_pagination_fields,
  9. workflow_run_detail_fields,
  10. workflow_run_node_execution_list_fields,
  11. workflow_run_pagination_fields,
  12. )
  13. from libs.helper import uuid_value
  14. from libs.login import login_required
  15. from models import App
  16. from models.model import AppMode
  17. from services.workflow_run_service import WorkflowRunService
  18. class AdvancedChatAppWorkflowRunListApi(Resource):
  19. @setup_required
  20. @login_required
  21. @account_initialization_required
  22. @get_app_model(mode=[AppMode.ADVANCED_CHAT])
  23. @marshal_with(advanced_chat_workflow_run_pagination_fields)
  24. def get(self, app_model: App):
  25. """
  26. Get advanced chat app workflow run list
  27. """
  28. parser = reqparse.RequestParser()
  29. parser.add_argument("last_id", type=uuid_value, location="args")
  30. parser.add_argument("limit", type=int_range(1, 100), required=False, default=20, location="args")
  31. args = parser.parse_args()
  32. workflow_run_service = WorkflowRunService()
  33. result = workflow_run_service.get_paginate_advanced_chat_workflow_runs(app_model=app_model, args=args)
  34. return result
  35. class WorkflowRunListApi(Resource):
  36. @setup_required
  37. @login_required
  38. @account_initialization_required
  39. @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
  40. @marshal_with(workflow_run_pagination_fields)
  41. def get(self, app_model: App):
  42. """
  43. Get workflow run list
  44. """
  45. parser = reqparse.RequestParser()
  46. parser.add_argument("last_id", type=uuid_value, location="args")
  47. parser.add_argument("limit", type=int_range(1, 100), required=False, default=20, location="args")
  48. args = parser.parse_args()
  49. workflow_run_service = WorkflowRunService()
  50. result = workflow_run_service.get_paginate_workflow_runs(app_model=app_model, args=args)
  51. return result
  52. class WorkflowRunDetailApi(Resource):
  53. @setup_required
  54. @login_required
  55. @account_initialization_required
  56. @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
  57. @marshal_with(workflow_run_detail_fields)
  58. def get(self, app_model: App, run_id):
  59. """
  60. Get workflow run detail
  61. """
  62. run_id = str(run_id)
  63. workflow_run_service = WorkflowRunService()
  64. workflow_run = workflow_run_service.get_workflow_run(app_model=app_model, run_id=run_id)
  65. return workflow_run
  66. class WorkflowRunNodeExecutionListApi(Resource):
  67. @setup_required
  68. @login_required
  69. @account_initialization_required
  70. @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
  71. @marshal_with(workflow_run_node_execution_list_fields)
  72. def get(self, app_model: App, run_id):
  73. """
  74. Get workflow run node execution list
  75. """
  76. run_id = str(run_id)
  77. workflow_run_service = WorkflowRunService()
  78. node_executions = workflow_run_service.get_workflow_run_node_executions(app_model=app_model, run_id=run_id)
  79. return {"data": node_executions}
  80. api.add_resource(AdvancedChatAppWorkflowRunListApi, "/apps/<uuid:app_id>/advanced-chat/workflow-runs")
  81. api.add_resource(WorkflowRunListApi, "/apps/<uuid:app_id>/workflow-runs")
  82. api.add_resource(WorkflowRunDetailApi, "/apps/<uuid:app_id>/workflow-runs/<uuid:run_id>")
  83. api.add_resource(WorkflowRunNodeExecutionListApi, "/apps/<uuid:app_id>/workflow-runs/<uuid:run_id>/node-executions")