Skip to content

API reference

vizro_experimental.chat

Chat component for Vizro dashboards (experimental).

Chat

Bases: VizroBaseModel

Chat component for conversational AI interfaces.

Parameters:

  • type (Literal['chat']) –

    Defaults to "chat".

  • actions (list[_BaseChatAction] | _BaseChatAction) –

    The action that handles responses. Pass an action instance directly; the field stores it as a single-element list to match Vizro's action-chain convention. Defaults to [].

  • placeholder (str) –

    Placeholder text for the input field. Defaults to "How can I help you?".

  • file_upload (bool) –

    Enable file upload functionality. Defaults to False.

  • example_questions (list[str]) –

    List of example questions to show in a popup menu. Defaults to [].

build

build()

Build the chat component layout.

Returns:

  • Div

    Dash HTML Div containing the complete chat interface.

pre_build

pre_build()

Set up callbacks for example questions during pre-build phase.

ChatAction

Bases: _BaseChatAction

Non-streaming chat action for synchronous response generation.

Subclass this to create custom chat actions that return complete responses.

Example
class my_chat(ChatAction):
    def generate_response(self, messages):
        return "Hello from my chat!"

outputs property

outputs

Define callback outputs for this action.

Returns:

  • list[str]

    List of output component references.

function

function(prompt, messages, uploaded_files=None)

Execute the chat action callback.

Parameters:

  • prompt (str) –

    User's input text.

  • messages (list[dict[str, Any]]) –

    Store-shaped history (role + content_json); mutated in place when sending.

  • uploaded_files (list[dict[str, str]] | None, default: None ) –

    File-store payload at send time. Snapshotted into the new user message as attachments so the bubble renders them and the file-store can clear.

Returns:

  • list[Any]

    List of outputs for store, hidden-messages, chat-input, file-store, and data-info

  • list[Any]

    (matching self.outputs).

generate_response

generate_response(messages, **kwargs)

Generate a chat response.

Parameters:

  • messages (list[Message]) –

    Parsed history: each item has role and content (decoded from store content_json).

  • **kwargs (Any, default: {} ) –

    Optional uploaded_files or other kwargs only if your implementation accepts them.

Returns:

  • str | Div

    Response content as string or Dash component (will be JSON-serialized automatically).

Raises:

  • NotImplementedError

    Must be implemented by subclass.

Message

Bases: TypedDict

Parsed chat item passed to generate_response (decoded content_json).

attachments is present on user turns that included file uploads — each entry has filename and content (base64 data URL). Only set when the original wire message carried it; absent on plain text turns.

StreamingChatAction

Bases: _BaseChatAction

Streaming chat action for real-time response generation via SSE.

Subclass this to create custom chat actions that stream responses in real-time.

Example
class my_streaming_chat(StreamingChatAction):
    def generate_response(self, messages):
        for chunk in ["Hello", " ", "World!"]:
            yield chunk

outputs property

outputs

Define callback outputs for this action.

Returns:

  • list[str]

    List of output component references.

function

function(prompt, messages, uploaded_files=None)

Execute the streaming chat action callback.

Parameters:

  • prompt (str) –

    User's input text.

  • messages (list[dict[str, Any]]) –

    Store-shaped history (role + content_json); mutated in place when sending.

  • uploaded_files (list[dict[str, str]] | None, default: None ) –

    File-store payload at send time. Snapshotted into the new user message as attachments so the bubble renders them and the file-store can clear.

Returns:

  • list[Any]

    List of outputs for store, hidden-messages, chat-input, SSE url, SSE options,

  • list[Any]

    file-store, and data-info (matching self.outputs).

generate_response

generate_response(messages, **kwargs)

Generate a streaming chat response.

Parameters:

  • messages (list[Message]) –

    Parsed history: each item has role and content (decoded from store content_json).

  • **kwargs (Any, default: {} ) –

    Optional uploaded_files or other kwargs only if your implementation accepts them.

Yields:

  • str

    Text chunks to stream to the client.

Raises:

  • NotImplementedError

    Must be implemented by subclass.

pre_build

pre_build()

Set up streaming callbacks and endpoint during pre-build phase.