AI.Stream.Event (AI SDK v0.0.1-rc.0)

View Source

Defines standard event types for streaming interactions with AI models.

These structured event types represent different kinds of data that can be emitted during a streaming interaction, allowing for standardized handling across different providers.

Summary

Functions

Converts a tuple format to an Event struct.

Converts an Event struct to a tuple format.

Types

t()

tuple_format()

@type tuple_format() ::
  {:text_delta, String.t()}
  | {:tool_call, map()}
  | {:finish, String.t()}
  | {:metadata, map()}
  | {:error, any()}

Functions

from_tuple(arg)

@spec from_tuple(tuple_format()) :: t()

Converts a tuple format to an Event struct.

Examples

iex> AI.Stream.Event.from_tuple({:text_delta, "Hello"})
%AI.Stream.Event.TextDelta{content: "Hello"}

to_tuple(arg1)

@spec to_tuple(t()) :: tuple_format()

Converts an Event struct to a tuple format.

Examples

iex> event = %AI.Stream.Event.TextDelta{content: "Hello"}
iex> AI.Stream.Event.to_tuple(event)
{:text_delta, "Hello"}