|
@@ -180,7 +180,7 @@ class AdvancedChatAppGenerateTaskPipeline(BasedGenerateTaskPipeline, WorkflowCyc
|
|
else:
|
|
else:
|
|
continue
|
|
continue
|
|
|
|
|
|
- raise Exception("Queue listening stopped unexpectedly.")
|
|
|
|
|
|
+ raise ValueError("queue listening stopped unexpectedly.")
|
|
|
|
|
|
def _to_stream_response(
|
|
def _to_stream_response(
|
|
self, generator: Generator[StreamResponse, None, None]
|
|
self, generator: Generator[StreamResponse, None, None]
|
|
@@ -291,9 +291,27 @@ class AdvancedChatAppGenerateTaskPipeline(BasedGenerateTaskPipeline, WorkflowCyc
|
|
yield self._workflow_start_to_stream_response(
|
|
yield self._workflow_start_to_stream_response(
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run
|
|
)
|
|
)
|
|
|
|
+ elif isinstance(
|
|
|
|
+ event,
|
|
|
|
+ QueueNodeRetryEvent,
|
|
|
|
+ ):
|
|
|
|
+ if not workflow_run:
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
+ workflow_node_execution = self._handle_workflow_node_execution_retried(
|
|
|
|
+ workflow_run=workflow_run, event=event
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ response = self._workflow_node_retry_to_stream_response(
|
|
|
|
+ event=event,
|
|
|
|
+ task_id=self._application_generate_entity.task_id,
|
|
|
|
+ workflow_node_execution=workflow_node_execution,
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ if response:
|
|
|
|
+ yield response
|
|
elif isinstance(event, QueueNodeStartedEvent):
|
|
elif isinstance(event, QueueNodeStartedEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
workflow_node_execution = self._handle_node_execution_start(workflow_run=workflow_run, event=event)
|
|
workflow_node_execution = self._handle_node_execution_start(workflow_run=workflow_run, event=event)
|
|
|
|
|
|
@@ -331,63 +349,48 @@ class AdvancedChatAppGenerateTaskPipeline(BasedGenerateTaskPipeline, WorkflowCyc
|
|
|
|
|
|
if response:
|
|
if response:
|
|
yield response
|
|
yield response
|
|
- elif isinstance(
|
|
|
|
- event,
|
|
|
|
- QueueNodeRetryEvent,
|
|
|
|
- ):
|
|
|
|
- workflow_node_execution = self._handle_workflow_node_execution_retried(
|
|
|
|
- workflow_run=workflow_run, event=event
|
|
|
|
- )
|
|
|
|
|
|
|
|
- response = self._workflow_node_retry_to_stream_response(
|
|
|
|
- event=event,
|
|
|
|
- task_id=self._application_generate_entity.task_id,
|
|
|
|
- workflow_node_execution=workflow_node_execution,
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- if response:
|
|
|
|
- yield response
|
|
|
|
elif isinstance(event, QueueParallelBranchRunStartedEvent):
|
|
elif isinstance(event, QueueParallelBranchRunStartedEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
yield self._workflow_parallel_branch_start_to_stream_response(
|
|
yield self._workflow_parallel_branch_start_to_stream_response(
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
)
|
|
)
|
|
elif isinstance(event, QueueParallelBranchRunSucceededEvent | QueueParallelBranchRunFailedEvent):
|
|
elif isinstance(event, QueueParallelBranchRunSucceededEvent | QueueParallelBranchRunFailedEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
yield self._workflow_parallel_branch_finished_to_stream_response(
|
|
yield self._workflow_parallel_branch_finished_to_stream_response(
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
)
|
|
)
|
|
elif isinstance(event, QueueIterationStartEvent):
|
|
elif isinstance(event, QueueIterationStartEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
yield self._workflow_iteration_start_to_stream_response(
|
|
yield self._workflow_iteration_start_to_stream_response(
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
)
|
|
)
|
|
elif isinstance(event, QueueIterationNextEvent):
|
|
elif isinstance(event, QueueIterationNextEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
yield self._workflow_iteration_next_to_stream_response(
|
|
yield self._workflow_iteration_next_to_stream_response(
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
)
|
|
)
|
|
elif isinstance(event, QueueIterationCompletedEvent):
|
|
elif isinstance(event, QueueIterationCompletedEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
yield self._workflow_iteration_completed_to_stream_response(
|
|
yield self._workflow_iteration_completed_to_stream_response(
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
|
|
)
|
|
)
|
|
elif isinstance(event, QueueWorkflowSucceededEvent):
|
|
elif isinstance(event, QueueWorkflowSucceededEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
if not graph_runtime_state:
|
|
if not graph_runtime_state:
|
|
- raise Exception("Graph runtime state not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
workflow_run = self._handle_workflow_run_success(
|
|
workflow_run = self._handle_workflow_run_success(
|
|
workflow_run=workflow_run,
|
|
workflow_run=workflow_run,
|
|
@@ -406,10 +409,10 @@ class AdvancedChatAppGenerateTaskPipeline(BasedGenerateTaskPipeline, WorkflowCyc
|
|
self._queue_manager.publish(QueueAdvancedChatMessageEndEvent(), PublishFrom.TASK_PIPELINE)
|
|
self._queue_manager.publish(QueueAdvancedChatMessageEndEvent(), PublishFrom.TASK_PIPELINE)
|
|
elif isinstance(event, QueueWorkflowPartialSuccessEvent):
|
|
elif isinstance(event, QueueWorkflowPartialSuccessEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
if not graph_runtime_state:
|
|
if not graph_runtime_state:
|
|
- raise Exception("Graph runtime state not initialized.")
|
|
|
|
|
|
+ raise ValueError("graph runtime state not initialized.")
|
|
|
|
|
|
workflow_run = self._handle_workflow_run_partial_success(
|
|
workflow_run = self._handle_workflow_run_partial_success(
|
|
workflow_run=workflow_run,
|
|
workflow_run=workflow_run,
|
|
@@ -429,10 +432,10 @@ class AdvancedChatAppGenerateTaskPipeline(BasedGenerateTaskPipeline, WorkflowCyc
|
|
self._queue_manager.publish(QueueAdvancedChatMessageEndEvent(), PublishFrom.TASK_PIPELINE)
|
|
self._queue_manager.publish(QueueAdvancedChatMessageEndEvent(), PublishFrom.TASK_PIPELINE)
|
|
elif isinstance(event, QueueWorkflowFailedEvent):
|
|
elif isinstance(event, QueueWorkflowFailedEvent):
|
|
if not workflow_run:
|
|
if not workflow_run:
|
|
- raise Exception("Workflow run not initialized.")
|
|
|
|
|
|
+ raise ValueError("workflow run not initialized.")
|
|
|
|
|
|
if not graph_runtime_state:
|
|
if not graph_runtime_state:
|
|
- raise Exception("Graph runtime state not initialized.")
|
|
|
|
|
|
+ raise ValueError("graph runtime state not initialized.")
|
|
|
|
|
|
workflow_run = self._handle_workflow_run_failed(
|
|
workflow_run = self._handle_workflow_run_failed(
|
|
workflow_run=workflow_run,
|
|
workflow_run=workflow_run,
|
|
@@ -522,7 +525,7 @@ class AdvancedChatAppGenerateTaskPipeline(BasedGenerateTaskPipeline, WorkflowCyc
|
|
yield self._message_replace_to_stream_response(answer=event.text)
|
|
yield self._message_replace_to_stream_response(answer=event.text)
|
|
elif isinstance(event, QueueAdvancedChatMessageEndEvent):
|
|
elif isinstance(event, QueueAdvancedChatMessageEndEvent):
|
|
if not graph_runtime_state:
|
|
if not graph_runtime_state:
|
|
- raise Exception("Graph runtime state not initialized.")
|
|
|
|
|
|
+ raise ValueError("graph runtime state not initialized.")
|
|
|
|
|
|
output_moderation_answer = self._handle_output_moderation_when_task_finished(self._task_state.answer)
|
|
output_moderation_answer = self._handle_output_moderation_when_task_finished(self._task_state.answer)
|
|
if output_moderation_answer:
|
|
if output_moderation_answer:
|