@@ -180,7 +180,7 @@ def _to_blocking_response(self, generator: Generator[StreamResponse, None, None]
180
180
else :
181
181
continue
182
182
183
- raise Exception ( "Queue listening stopped unexpectedly." )
183
+ raise ValueError ( "queue listening stopped unexpectedly." )
184
184
185
185
def _to_stream_response (
186
186
self , generator : Generator [StreamResponse , None , None ]
@@ -291,9 +291,27 @@ def _process_stream_response(
291
291
yield self ._workflow_start_to_stream_response (
292
292
task_id = self ._application_generate_entity .task_id , workflow_run = workflow_run
293
293
)
294
+ elif isinstance (
295
+ event ,
296
+ QueueNodeRetryEvent ,
297
+ ):
298
+ if not workflow_run :
299
+ raise ValueError ("workflow run not initialized." )
300
+ workflow_node_execution = self ._handle_workflow_node_execution_retried (
301
+ workflow_run = workflow_run , event = event
302
+ )
303
+
304
+ response = self ._workflow_node_retry_to_stream_response (
305
+ event = event ,
306
+ task_id = self ._application_generate_entity .task_id ,
307
+ workflow_node_execution = workflow_node_execution ,
308
+ )
309
+
310
+ if response :
311
+ yield response
294
312
elif isinstance (event , QueueNodeStartedEvent ):
295
313
if not workflow_run :
296
- raise Exception ( "Workflow run not initialized." )
314
+ raise ValueError ( "workflow run not initialized." )
297
315
298
316
workflow_node_execution = self ._handle_node_execution_start (workflow_run = workflow_run , event = event )
299
317
@@ -331,63 +349,48 @@ def _process_stream_response(
331
349
332
350
if response :
333
351
yield response
334
- elif isinstance (
335
- event ,
336
- QueueNodeRetryEvent ,
337
- ):
338
- workflow_node_execution = self ._handle_workflow_node_execution_retried (
339
- workflow_run = workflow_run , event = event
340
- )
341
352
342
- response = self ._workflow_node_retry_to_stream_response (
343
- event = event ,
344
- task_id = self ._application_generate_entity .task_id ,
345
- workflow_node_execution = workflow_node_execution ,
346
- )
347
-
348
- if response :
349
- yield response
350
353
elif isinstance (event , QueueParallelBranchRunStartedEvent ):
351
354
if not workflow_run :
352
- raise Exception ( "Workflow run not initialized." )
355
+ raise ValueError ( "workflow run not initialized." )
353
356
354
357
yield self ._workflow_parallel_branch_start_to_stream_response (
355
358
task_id = self ._application_generate_entity .task_id , workflow_run = workflow_run , event = event
356
359
)
357
360
elif isinstance (event , QueueParallelBranchRunSucceededEvent | QueueParallelBranchRunFailedEvent ):
358
361
if not workflow_run :
359
- raise Exception ( "Workflow run not initialized." )
362
+ raise ValueError ( "workflow run not initialized." )
360
363
361
364
yield self ._workflow_parallel_branch_finished_to_stream_response (
362
365
task_id = self ._application_generate_entity .task_id , workflow_run = workflow_run , event = event
363
366
)
364
367
elif isinstance (event , QueueIterationStartEvent ):
365
368
if not workflow_run :
366
- raise Exception ( "Workflow run not initialized." )
369
+ raise ValueError ( "workflow run not initialized." )
367
370
368
371
yield self ._workflow_iteration_start_to_stream_response (
369
372
task_id = self ._application_generate_entity .task_id , workflow_run = workflow_run , event = event
370
373
)
371
374
elif isinstance (event , QueueIterationNextEvent ):
372
375
if not workflow_run :
373
- raise Exception ( "Workflow run not initialized." )
376
+ raise ValueError ( "workflow run not initialized." )
374
377
375
378
yield self ._workflow_iteration_next_to_stream_response (
376
379
task_id = self ._application_generate_entity .task_id , workflow_run = workflow_run , event = event
377
380
)
378
381
elif isinstance (event , QueueIterationCompletedEvent ):
379
382
if not workflow_run :
380
- raise Exception ( "Workflow run not initialized." )
383
+ raise ValueError ( "workflow run not initialized." )
381
384
382
385
yield self ._workflow_iteration_completed_to_stream_response (
383
386
task_id = self ._application_generate_entity .task_id , workflow_run = workflow_run , event = event
384
387
)
385
388
elif isinstance (event , QueueWorkflowSucceededEvent ):
386
389
if not workflow_run :
387
- raise Exception ( "Workflow run not initialized." )
390
+ raise ValueError ( "workflow run not initialized." )
388
391
389
392
if not graph_runtime_state :
390
- raise Exception ( "Graph runtime state not initialized." )
393
+ raise ValueError ( "workflow run not initialized." )
391
394
392
395
workflow_run = self ._handle_workflow_run_success (
393
396
workflow_run = workflow_run ,
@@ -406,10 +409,10 @@ def _process_stream_response(
406
409
self ._queue_manager .publish (QueueAdvancedChatMessageEndEvent (), PublishFrom .TASK_PIPELINE )
407
410
elif isinstance (event , QueueWorkflowPartialSuccessEvent ):
408
411
if not workflow_run :
409
- raise Exception ( "Workflow run not initialized." )
412
+ raise ValueError ( "workflow run not initialized." )
410
413
411
414
if not graph_runtime_state :
412
- raise Exception ( "Graph runtime state not initialized." )
415
+ raise ValueError ( "graph runtime state not initialized." )
413
416
414
417
workflow_run = self ._handle_workflow_run_partial_success (
415
418
workflow_run = workflow_run ,
@@ -429,10 +432,10 @@ def _process_stream_response(
429
432
self ._queue_manager .publish (QueueAdvancedChatMessageEndEvent (), PublishFrom .TASK_PIPELINE )
430
433
elif isinstance (event , QueueWorkflowFailedEvent ):
431
434
if not workflow_run :
432
- raise Exception ( "Workflow run not initialized." )
435
+ raise ValueError ( "workflow run not initialized." )
433
436
434
437
if not graph_runtime_state :
435
- raise Exception ( "Graph runtime state not initialized." )
438
+ raise ValueError ( "graph runtime state not initialized." )
436
439
437
440
workflow_run = self ._handle_workflow_run_failed (
438
441
workflow_run = workflow_run ,
@@ -522,7 +525,7 @@ def _process_stream_response(
522
525
yield self ._message_replace_to_stream_response (answer = event .text )
523
526
elif isinstance (event , QueueAdvancedChatMessageEndEvent ):
524
527
if not graph_runtime_state :
525
- raise Exception ( "Graph runtime state not initialized." )
528
+ raise ValueError ( "graph runtime state not initialized." )
526
529
527
530
output_moderation_answer = self ._handle_output_moderation_when_task_finished (self ._task_state .answer )
528
531
if output_moderation_answer :
0 commit comments