Skip to content

Commit

Permalink
fix: streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Jan 13, 2025
1 parent d76a748 commit c16f58e
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/openai/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,6 @@ def __stream__(self) -> Iterator[_T]:

yield process_data(data=data, cast_to=cast_to, response=response)

else:
data = sse.json()

if sse.event == "error" and is_mapping(data) and data.get("error"):
message = None
error = data.get("error")
if is_mapping(error):
message = error.get("message")
if not message or not isinstance(message, str):
message = "An error occurred during streaming"

raise APIError(
message=message,
request=self.response.request,
body=data["error"],
)

yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response)

# Ensure the entire stream is consumed
for _sse in iterator:
...
Expand Down Expand Up @@ -177,25 +158,6 @@ async def __stream__(self) -> AsyncIterator[_T]:

yield process_data(data=data, cast_to=cast_to, response=response)

else:
data = sse.json()

if sse.event == "error" and is_mapping(data) and data.get("error"):
message = None
error = data.get("error")
if is_mapping(error):
message = error.get("message")
if not message or not isinstance(message, str):
message = "An error occurred during streaming"

raise APIError(
message=message,
request=self.response.request,
body=data["error"],
)

yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response)

# Ensure the entire stream is consumed
async for _sse in iterator:
...
Expand Down

0 comments on commit c16f58e

Please sign in to comment.