Streaming outputs, reducing latency, SSEs
run_remote
as a bytes- or string-iterator, e.g.:
data
, event
and potentially
other fields and content-type text/event-stream
.
However, the SSE specification is not opinionated regarding what exactly is
encoded in data
and what event
-types exist - you have to make up your schema
that is useful for the client that consumes the data.
Header
pydantic
model.Item
pydantic
model.Footer
pydantic
model.StreamType
-object:
STREAM_TYPES
to create a matching stream writer:
yield_header
and yield_footer
methods are available on the writer.
The writer serializes the pydantic data to bytes
, so you can also
efficiently represent numeric data (see the
binary IO guide).
StreamReader
is created form your StreamTypes
. Besides the
types, you connect the reader to the bytes generator that you obtain from the
remote invocation of the streaming Chainlet:
read_header
and
read_footer
methods.
StreamReader
only needs pydantic
, no other Chains
dependencies. So you can take that implementation code in isolation and
integrate it in your client code.