|
15 | 15 | QueueIterationCompletedEvent,
|
16 | 16 | QueueIterationNextEvent,
|
17 | 17 | QueueIterationStartEvent,
|
| 18 | + QueueNodeExceptionEvent, |
18 | 19 | QueueNodeFailedEvent,
|
19 | 20 | QueueNodeInIterationFailedEvent,
|
20 | 21 | QueueNodeStartedEvent,
|
|
26 | 27 | QueueStopEvent,
|
27 | 28 | QueueTextChunkEvent,
|
28 | 29 | QueueWorkflowFailedEvent,
|
| 30 | + QueueWorkflowPartialSuccessEvent, |
29 | 31 | QueueWorkflowStartedEvent,
|
30 | 32 | QueueWorkflowSucceededEvent,
|
31 | 33 | )
|
@@ -276,7 +278,7 @@ def _process_stream_response(
|
276 | 278 |
|
277 | 279 | if response:
|
278 | 280 | yield response
|
279 |
| - elif isinstance(event, QueueNodeFailedEvent | QueueNodeInIterationFailedEvent): |
| 281 | + elif isinstance(event, QueueNodeFailedEvent | QueueNodeInIterationFailedEvent | QueueNodeExceptionEvent): |
280 | 282 | workflow_node_execution = self._handle_workflow_node_execution_failed(event)
|
281 | 283 |
|
282 | 284 | response = self._workflow_node_finish_to_stream_response(
|
@@ -345,29 +347,81 @@ def _process_stream_response(
|
345 | 347 | yield self._workflow_finish_to_stream_response(
|
346 | 348 | task_id=self._application_generate_entity.task_id, workflow_run=workflow_run
|
347 | 349 | )
|
348 |
| - elif isinstance(event, QueueWorkflowFailedEvent | QueueStopEvent): |
| 350 | + elif isinstance(event, QueueWorkflowPartialSuccessEvent): |
349 | 351 | if not workflow_run:
|
350 | 352 | raise Exception("Workflow run not initialized.")
|
351 | 353 |
|
352 | 354 | if not graph_runtime_state:
|
353 | 355 | raise Exception("Graph runtime state not initialized.")
|
354 | 356 |
|
355 |
| - workflow_run = self._handle_workflow_run_failed( |
| 357 | + workflow_run = self._handle_workflow_run_partial_success( |
356 | 358 | workflow_run=workflow_run,
|
357 | 359 | start_at=graph_runtime_state.start_at,
|
358 | 360 | total_tokens=graph_runtime_state.total_tokens,
|
359 | 361 | total_steps=graph_runtime_state.node_run_steps,
|
360 |
| - status=WorkflowRunStatus.FAILED |
361 |
| - if isinstance(event, QueueWorkflowFailedEvent) |
362 |
| - else WorkflowRunStatus.STOPPED, |
363 |
| - error=event.error if isinstance(event, QueueWorkflowFailedEvent) else event.get_stop_reason(), |
| 362 | + outputs=event.outputs, |
| 363 | + exceptions_count=event.exceptions_count, |
364 | 364 | conversation_id=None,
|
365 | 365 | trace_manager=trace_manager,
|
366 | 366 | )
|
367 | 367 |
|
368 | 368 | # save workflow app log
|
369 | 369 | self._save_workflow_app_log(workflow_run)
|
370 | 370 |
|
| 371 | + yield self._workflow_finish_to_stream_response( |
| 372 | + task_id=self._application_generate_entity.task_id, workflow_run=workflow_run |
| 373 | + ) |
| 374 | + elif isinstance(event, QueueWorkflowFailedEvent | QueueStopEvent): |
| 375 | + if not workflow_run: |
| 376 | + raise Exception("Workflow run not initialized.") |
| 377 | + |
| 378 | + if not graph_runtime_state: |
| 379 | + raise Exception("Graph runtime state not initialized.") |
| 380 | + handle_args = { |
| 381 | + "workflow_run": workflow_run, |
| 382 | + "start_at": graph_runtime_state.start_at, |
| 383 | + "total_tokens": graph_runtime_state.total_tokens, |
| 384 | + "total_steps": graph_runtime_state.node_run_steps, |
| 385 | + "status": WorkflowRunStatus.FAILED |
| 386 | + if isinstance(event, QueueWorkflowFailedEvent) |
| 387 | + else WorkflowRunStatus.STOPPED, |
| 388 | + "error": event.error if isinstance(event, QueueWorkflowFailedEvent) else event.get_stop_reason(), |
| 389 | + "conversation_id": None, |
| 390 | + "trace_manager": trace_manager, |
| 391 | + "exceptions_count": event.exceptions_count if isinstance(event, QueueWorkflowFailedEvent) else 0, |
| 392 | + } |
| 393 | + workflow_run = self._handle_workflow_run_failed(**handle_args) |
| 394 | + |
| 395 | + # save workflow app log |
| 396 | + self._save_workflow_app_log(workflow_run) |
| 397 | + |
| 398 | + yield self._workflow_finish_to_stream_response( |
| 399 | + task_id=self._application_generate_entity.task_id, workflow_run=workflow_run |
| 400 | + ) |
| 401 | + elif isinstance(event, QueueWorkflowPartialSuccessEvent): |
| 402 | + if not workflow_run: |
| 403 | + raise Exception("Workflow run not initialized.") |
| 404 | + |
| 405 | + if not graph_runtime_state: |
| 406 | + raise Exception("Graph runtime state not initialized.") |
| 407 | + handle_args = { |
| 408 | + "workflow_run": workflow_run, |
| 409 | + "start_at": graph_runtime_state.start_at, |
| 410 | + "total_tokens": graph_runtime_state.total_tokens, |
| 411 | + "total_steps": graph_runtime_state.node_run_steps, |
| 412 | + "status": WorkflowRunStatus.FAILED |
| 413 | + if isinstance(event, QueueWorkflowFailedEvent) |
| 414 | + else WorkflowRunStatus.STOPPED, |
| 415 | + "error": event.error if isinstance(event, QueueWorkflowFailedEvent) else event.get_stop_reason(), |
| 416 | + "conversation_id": None, |
| 417 | + "trace_manager": trace_manager, |
| 418 | + "exceptions_count": event.exceptions_count, |
| 419 | + } |
| 420 | + workflow_run = self._handle_workflow_run_partial_success(**handle_args) |
| 421 | + |
| 422 | + # save workflow app log |
| 423 | + self._save_workflow_app_log(workflow_run) |
| 424 | + |
371 | 425 | yield self._workflow_finish_to_stream_response(
|
372 | 426 | task_id=self._application_generate_entity.task_id, workflow_run=workflow_run
|
373 | 427 | )
|
|
0 commit comments