MCPcopy
hub / github.com/openai/openai-python / _aiter_chunks

Method _aiter_chunks

src/openai/_streaming.py:327–337  ·  view source on GitHub ↗

Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks

(self, iterator: AsyncIterator[bytes])

Source from the content-addressed store, hash-verified

325 yield sse
326
327 async def _aiter_chunks(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[bytes]:
328 """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
329 data = b""
330 async for chunk in iterator:
331 for line in chunk.splitlines(keepends=True):
332 data += line
333 if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
334 yield data
335 data = b""
336 if data:
337 yield data
338
339 def decode(self, line: str) -> ServerSentEvent | None:
340 # See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501

Callers 1

aiter_bytesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected