MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / make_stream_iterator

Function make_stream_iterator

tests/test_streaming.py:284–302  ·  view source on GitHub ↗
(
    content: Iterator[bytes],
    *,
    sync: bool,
    client: Anthropic,
    async_client: AsyncAnthropic,
)

Source from the content-addressed store, hash-verified

282# Unlike make_event_iterator which only parses SSE events using _iter_events(),
283# this helper uses __stream__() to process the full stream pipeline including
284# parsing message objects and converting error events into raised exceptions.
285def make_stream_iterator(
286 content: Iterator[bytes],
287 *,
288 sync: bool,
289 client: Anthropic,
290 async_client: AsyncAnthropic,
291) -> AsyncIterator[object] | Iterator[object]:
292 if sync:
293 return Stream(
294 cast_to=object,
295 client=client,
296 response=httpx.Response(200, content=content, request=httpx.Request("GET", "https://example.com")),
297 ).__stream__()
298
299 return AsyncStream(
300 cast_to=object,
301 client=async_client,
302 response=httpx.Response(200, content=to_aiter(content), request=httpx.Request("GET", "https://example.com")),
303 ).__stream__()

Callers 1

test_error_typeFunction · 0.85

Calls 4

StreamClass · 0.90
AsyncStreamClass · 0.90
to_aiterFunction · 0.70
__stream__Method · 0.45

Tested by

no test coverage detected