When conversing, you can set "stream": true to incrementally stream the response using server-sent events (SSE).

Streaming with SDKs

Both the Python and Typescript/Javascript SDKs provide convenient APIs to stream responses.

from datagrid_ai import Datagrid

datagrid = Datagrid()
response = datagrid.converse(
    prompt="prompt",
    stream=True,
)

for event in response:
    if (event.event == "delta"):
        print(event.delta.text)

Event types

Each server-sent event includes a named event type and associated JSON data. Each event will use an SSE event name (e.g. event: delta), and include the matching event type in its data.

Each stream uses the following event flow:

  1. start: Indicates the start of the conversation and contains the conversation_id and agent_id used to answer the prompt.
  2. delta: contains the delta object with the changes to the message.
  3. end: Indicates the end of the conversation.