diff --git a/src/engine/ov_genai/llm.py b/src/engine/ov_genai/llm.py index 12bcdf8..0b3fe42 100755 --- a/src/engine/ov_genai/llm.py +++ b/src/engine/ov_genai/llm.py @@ -141,8 +141,15 @@ async def _run_generation(): generation_kwargs, streamer ) + def _generation_exception_handler(task: asyncio.Task): + exc = task.exception() + if exc and not task.cancelled(): + # Force break the below loop + streamer.text_queue.put_nowait(None) + raise exc gen_task = asyncio.create_task(_run_generation()) + gen_task.add_done_callback(_generation_exception_handler) try: while True: diff --git a/src/engine/ov_genai/vlm.py b/src/engine/ov_genai/vlm.py index 054bb54..6015ef7 100644 --- a/src/engine/ov_genai/vlm.py +++ b/src/engine/ov_genai/vlm.py @@ -189,8 +189,15 @@ async def _run_generation(): generation_config=generation_kwargs, streamer=streamer, ) + def _generation_exception_handler(task: asyncio.Task): + exc = task.exception() + if exc and not task.cancelled(): + # Force break the below loop + streamer.text_queue.put_nowait(None) + raise exc gen_task = asyncio.create_task(_run_generation()) + gen_task.add_done_callback(_generation_exception_handler) try: while True: