Skip to content

Commit 246bc5b

Browse files
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 <[email protected]> --------- Co-authored-by: SenorSpes <[email protected]> Co-authored-by: Robert Craigie <[email protected]>
1 parent fad098f commit 246bc5b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/openai/lib/streaming/chat/_completions.py

+2
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS
438438
choice_snapshot.message.content
439439
and not choice_snapshot.message.refusal
440440
and is_given(self._rich_response_format)
441+
# partial parsing fails on white-space
442+
and choice_snapshot.message.content.strip()
441443
):
442444
choice_snapshot.message.parsed = from_json(
443445
bytes(choice_snapshot.message.content, "utf-8"),

0 commit comments

Comments
 (0)