Skip to content

Update _completions.py #2422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/openai/lib/streaming/chat/_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,15 @@ def current_completion_snapshot(self) -> ParsedChatCompletionSnapshot:

async def __stream__(self) -> AsyncIterator[ChatCompletionStreamEvent[ResponseFormatT]]:
async for sse_event in self._raw_stream:
if not _is_valid_chat_completion_chunk_weak(sse_event):
valid = _is_valid_chat_completion_chunk_weak(sse_event)
if valid is False:
continue
Comment on lines +239 to 241
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this makes sense, when can this function return anything other than a bool?

events_to_fire = self._state.handle_chunk(sse_event)

try:
events_to_fire = self._state.handle_chunk(sse_event)
except Exception as e:
raise RuntimeError("Stream processing failed while handling a chunk") from e

for event in events_to_fire:
yield event

Expand Down