feat: workflow/chatflow api support async
parent
0babdffe3e
commit
de0d9f96b8
@ -0,0 +1,27 @@
|
||||
from flask_restful import Resource, marshal_with
|
||||
|
||||
from controllers.service_api import api
|
||||
from controllers.service_api.wraps import validate_app_token
|
||||
from fields.workflow_run_fields import (
|
||||
workflow_run_node_execution_fields,
|
||||
)
|
||||
from models import App
|
||||
from services.workflow_run_service import WorkflowRunService
|
||||
|
||||
|
||||
class WorkflowRunDetailApi(Resource):
|
||||
@validate_app_token
|
||||
@marshal_with(workflow_run_node_execution_fields)
|
||||
def get(self, app_model: App, run_id):
|
||||
"""
|
||||
Get workflow run detail
|
||||
"""
|
||||
run_id = str(run_id)
|
||||
|
||||
workflow_run_service = WorkflowRunService()
|
||||
workflow_run = workflow_run_service.get_workflow_run(app_model=app_model, run_id=run_id)
|
||||
|
||||
return workflow_run
|
||||
|
||||
|
||||
api.add_resource(WorkflowRunDetailApi, "/apps/workflow-runs/<uuid:run_id>", endpoint="workflow_run_detail")
|
||||
@ -0,0 +1,69 @@
|
||||
from core.app.entities.queue_entities import QueueEvent, AppQueueEvent
|
||||
from core.app.entities.task_entities import StreamEvent, StreamResponse
|
||||
|
||||
workflow_queue_task_map = {
|
||||
StreamEvent.PING: QueueEvent.PING,
|
||||
StreamEvent.ERROR: QueueEvent.ERROR,
|
||||
StreamEvent.MESSAGE: QueueEvent.TEXT_CHUNK,
|
||||
StreamEvent.MESSAGE_END: QueueEvent.MESSAGE_END,
|
||||
StreamEvent.TTS_MESSAGE: QueueEvent.TEXT_CHUNK,
|
||||
StreamEvent.TTS_MESSAGE_END: QueueEvent.MESSAGE_END,
|
||||
StreamEvent.MESSAGE_FILE: QueueEvent.MESSAGE_FILE,
|
||||
StreamEvent.MESSAGE_REPLACE: QueueEvent.MESSAGE_REPLACE,
|
||||
StreamEvent.AGENT_THOUGHT: QueueEvent.AGENT_THOUGHT,
|
||||
StreamEvent.AGENT_MESSAGE: QueueEvent.AGENT_MESSAGE,
|
||||
StreamEvent.WORKFLOW_STARTED: QueueEvent.WORKFLOW_STARTED,
|
||||
StreamEvent.WORKFLOW_FINISHED: QueueEvent.WORKFLOW_SUCCEEDED,
|
||||
StreamEvent.NODE_STARTED: QueueEvent.NODE_STARTED,
|
||||
StreamEvent.NODE_FINISHED: QueueEvent.NODE_SUCCEEDED,
|
||||
StreamEvent.NODE_RETRY: QueueEvent.RETRY,
|
||||
StreamEvent.PARALLEL_BRANCH_STARTED: QueueEvent.PARALLEL_BRANCH_RUN_STARTED,
|
||||
StreamEvent.PARALLEL_BRANCH_FINISHED: QueueEvent.PARALLEL_BRANCH_RUN_SUCCEEDED,
|
||||
StreamEvent.ITERATION_STARTED: QueueEvent.ITERATION_START,
|
||||
StreamEvent.ITERATION_NEXT: QueueEvent.ITERATION_NEXT,
|
||||
StreamEvent.ITERATION_COMPLETED: QueueEvent.ITERATION_COMPLETED,
|
||||
StreamEvent.LOOP_STARTED: QueueEvent.LOOP_START,
|
||||
StreamEvent.LOOP_NEXT: QueueEvent.LOOP_NEXT,
|
||||
StreamEvent.LOOP_COMPLETED: QueueEvent.LOOP_COMPLETED,
|
||||
StreamEvent.TEXT_CHUNK: QueueEvent.TEXT_CHUNK,
|
||||
StreamEvent.TEXT_REPLACE: QueueEvent.MESSAGE_REPLACE,
|
||||
StreamEvent.AGENT_LOG: QueueEvent.AGENT_LOG,
|
||||
|
||||
}
|
||||
|
||||
advance_chat_queue_task_map = {
|
||||
StreamEvent.PING: QueueEvent.PING,
|
||||
StreamEvent.ERROR: QueueEvent.ERROR,
|
||||
StreamEvent.MESSAGE: QueueEvent.TEXT_CHUNK,
|
||||
StreamEvent.MESSAGE_END: QueueEvent.ADVANCED_CHAT_MESSAGE_END,
|
||||
StreamEvent.TTS_MESSAGE: QueueEvent.TEXT_CHUNK,
|
||||
StreamEvent.TTS_MESSAGE_END: QueueEvent.MESSAGE_END,
|
||||
StreamEvent.MESSAGE_FILE: QueueEvent.MESSAGE_FILE,
|
||||
StreamEvent.MESSAGE_REPLACE: QueueEvent.MESSAGE_REPLACE,
|
||||
StreamEvent.AGENT_THOUGHT: QueueEvent.AGENT_THOUGHT,
|
||||
StreamEvent.AGENT_MESSAGE: QueueEvent.AGENT_MESSAGE,
|
||||
StreamEvent.WORKFLOW_STARTED: QueueEvent.WORKFLOW_STARTED,
|
||||
StreamEvent.WORKFLOW_FINISHED: QueueEvent.WORKFLOW_SUCCEEDED,
|
||||
StreamEvent.NODE_STARTED: QueueEvent.NODE_STARTED,
|
||||
StreamEvent.NODE_FINISHED: QueueEvent.NODE_SUCCEEDED,
|
||||
StreamEvent.NODE_RETRY: QueueEvent.RETRY,
|
||||
StreamEvent.PARALLEL_BRANCH_STARTED: QueueEvent.PARALLEL_BRANCH_RUN_STARTED,
|
||||
StreamEvent.PARALLEL_BRANCH_FINISHED: QueueEvent.PARALLEL_BRANCH_RUN_SUCCEEDED,
|
||||
StreamEvent.ITERATION_STARTED: QueueEvent.ITERATION_START,
|
||||
StreamEvent.ITERATION_NEXT: QueueEvent.ITERATION_NEXT,
|
||||
StreamEvent.ITERATION_COMPLETED: QueueEvent.ITERATION_COMPLETED,
|
||||
StreamEvent.LOOP_STARTED: QueueEvent.LOOP_START,
|
||||
StreamEvent.LOOP_NEXT: QueueEvent.LOOP_NEXT,
|
||||
StreamEvent.LOOP_COMPLETED: QueueEvent.LOOP_COMPLETED,
|
||||
StreamEvent.TEXT_CHUNK: QueueEvent.TEXT_CHUNK,
|
||||
StreamEvent.TEXT_REPLACE: QueueEvent.MESSAGE_REPLACE,
|
||||
StreamEvent.AGENT_LOG: QueueEvent.AGENT_LOG,
|
||||
}
|
||||
|
||||
|
||||
class ForwardQueueMessage(AppQueueEvent):
|
||||
"""
|
||||
ForwardQueueMessage entity
|
||||
"""
|
||||
event: QueueEvent = QueueEvent.PING
|
||||
response: StreamResponse
|
||||
Loading…
Reference in New Issue