MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / stream_response

Function stream_response

tests/lib/threads/helpers.py:415–434  ·  view source on GitHub ↗

A streamed reply. With `message_stop=False` the body ends after `message_delta`, as when the connection drops just before the last event.

(
    id: str,
    text: str = "Hello there!",
    *,
    tool_use_id: str | None = None,
    container: str | None = None,
    stop_reason: str | None = None,
    iterations: list[Any] | None = None,
    message_stop: bool = True,
)

Source from the content-addressed store, hash-verified

413
414
415def stream_response(
416 id: str,
417 text: str = "Hello there!",
418 *,
419 tool_use_id: str | None = None,
420 container: str | None = None,
421 stop_reason: str | None = None,
422 iterations: list[Any] | None = None,
423 message_stop: bool = True,
424) -> httpx2.Response:
425 """A streamed reply. With `message_stop=False` the body ends after `message_delta`, as when the connection drops
426 just before the last event."""
427 body = list(
428 _sse_body(
429 id, text, tool_use_id=tool_use_id, container=container, stop_reason=stop_reason, iterations=iterations
430 )
431 )
432 if not message_stop:
433 del body[-3:] # the `message_stop` event's three lines
434 return httpx2.Response(200, headers={"content-type": "text/event-stream"}, content=iter(body))
435
436
437def async_stream_response(

Calls 1

_sse_bodyFunction · 0.85