Skip to content

Commit

Permalink
fix: add a check to handle empty or newline-only strings before calli…
Browse files Browse the repository at this point in the history
…ng `from_json`
  • Loading branch information
maesta7 committed Jan 11, 2025
1 parent 33e4085 commit a75ff6e
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/openai/lib/streaming/chat/_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS
choice_snapshot.message.content
and not choice_snapshot.message.refusal
and is_given(self._rich_response_format)
and choice_snapshot.message.content.strip() # Add filter to ensure no parsing errors
):
choice_snapshot.message.parsed = from_json(
bytes(choice_snapshot.message.content, "utf-8"),
Expand Down

0 comments on commit a75ff6e

Please sign in to comment.