AI.Stream.Transformer behaviour (AI SDK v0.0.1-rc.0)
View SourceBehaviour for stream transformers that convert provider-specific streams to standardized events.
Stream transformers are responsible for:
- Taking provider-specific streaming events
- Converting them into standardized AI.Stream.Event structs
- Handling provider-specific event formats and quirks
This separation of concerns allows provider modules to focus on API communication while stream transformers handle the interpretation of streaming data formats.
Summary
Callbacks
Transforms a provider-specific event stream into a stream of standardized events.
Functions
Utility function to convert basic tuple event formats to AI.Stream.Event structs.
Callbacks
@callback transform(source_stream :: Enumerable.t(), options :: map()) :: Enumerable.t()
Transforms a provider-specific event stream into a stream of standardized events.
Takes a source stream and any provider-specific options, and returns a new stream that emits standardized AI.Stream.Event structs.
Parameters
source_stream
- The original stream from the provider APIoptions
- Additional options specific to this transformer (if any)
Returns
- A Stream that emits AI.Stream.Event structs
Functions
@spec convert_tuple_to_event(tuple()) :: AI.Stream.Event.t()
Utility function to convert basic tuple event formats to AI.Stream.Event structs.
This helper can be used by transformer implementations to simplify conversion of simple event tuples to Event structs.
Parameters
tuple_event
- An event in tuple format (e.g., {:text_delta, content})
Returns
- A corresponding AI.Stream.Event struct