Commit b3f0daf3

Pon Pongwachirin <138108569+maesta7@users.noreply.github.com>
2025-04-30 23:46:30
fix(parsing): handle whitespace only strings (#2007)
* fix: add a check to handle empty or newline-only strings before calling `from_json` * style: adjust comment format for better readability Co-authored-by: Robert Craigie <robert@craigie.dev> --------- Co-authored-by: SenorSpes <138108569+senorNox@users.noreply.github.com> Co-authored-by: Robert Craigie <robert@craigie.dev>
1 parent fad098f
Changed files (1)
src
openai
lib
streaming
src/openai/lib/streaming/chat/_completions.py
@@ -438,6 +438,8 @@ class ChatCompletionStreamState(Generic[ResponseFormatT]):
                 choice_snapshot.message.content
                 and not choice_snapshot.message.refusal
                 and is_given(self._rich_response_format)
+                # partial parsing fails on white-space
+                and choice_snapshot.message.content.strip()
             ):
                 choice_snapshot.message.parsed = from_json(
                     bytes(choice_snapshot.message.content, "utf-8"),