From 7f333407f28ae5c5b11f2a5e29fc420d1b7a1186 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 2 Aug 2026 16:49:04 -0400 Subject: [PATCH] refac --- cptr/utils/ai.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cptr/utils/ai.py b/cptr/utils/ai.py index 91d614b..3d103f5 100644 --- a/cptr/utils/ai.py +++ b/cptr/utils/ai.py @@ -61,7 +61,14 @@ _STREAM_TIMEOUT = httpx.Timeout( read=STREAM_READ_TIMEOUT_SECONDS, write=STREAM_WRITE_TIMEOUT_SECONDS, ) + + +class EmptyCompletionError(RuntimeError): + pass + + _STREAM_RETRY_ERRORS = ( + EmptyCompletionError, httpx.ConnectError, httpx.ConnectTimeout, httpx.HTTPStatusError, @@ -799,7 +806,7 @@ async def stream_openai_completions( emitted = True yield {"type": "output", "item": item} if not emitted: - raise RuntimeError( + raise EmptyCompletionError( "Upstream provider returned an empty completion with no text, " "output items, tool calls, or usage tokens." )