Components¶
Component handling for the streamlit_rich_message_history package.
This module defines the core MessageComponent class that detects, processes, and renders different types of content in a Streamlit application.
- class streamlit_rich_message_history.components.MessageComponent(content, component_type=None, title=None, description=None, expanded=False, **kwargs)[source]¶
Bases:
object
Base class for all message components with automatic type detection.
This class handles the automatic detection, proper rendering, and error handling for different types of content within a message in a Streamlit application.
- content¶
The actual content to be displayed
- component_type¶
The type of component (automatically detected if not specified)
- title¶
Optional title for the component
- description¶
Optional description text for the component
- expanded¶
Whether expandable sections should be expanded by default
- kwargs¶
Additional keyword arguments for rendering
- __init__(content, component_type=None, title=None, description=None, expanded=False, **kwargs)[source]¶
Initialize a new message component.
- Parameters:
content (
Any
) – The content to be displayedcomponent_type (
Optional
[ComponentType
]) – Manually specify the component type (auto-detected if None)title (
Optional
[str
]) – Optional title for the component (creates an expander if provided)description (
Optional
[str
]) – Optional description text for the componentexpanded (
bool
) – Whether expandable sections should be expanded by default**kwargs – Additional keyword arguments that control rendering behavior Special flags include: - is_error: Treat string content as an error message - is_code: Treat string content as code with syntax highlighting - language: The programming language for code highlighting - is_metric: Treat numeric content as a metric - is_table: Treat content as a static table - is_json: Treat dictionaries or lists as JSON data - is_html: Treat string content as HTML