Data object
TheData object is a Pydantic model that serves as a container for storing and manipulating data. It carries data, a dictionary that can be accessed as attributes, and uses text_key to specify which key in the dictionary should be considered the primary text content.
- Main Attributes:
text_key: Specifies the key to retrieve the primary text data.data: A dictionary to store additional data.default_value: default value when thetext_keyis not present in thedatadictionary.
Create a Data Object
- Create a
Dataobject by directly assigning key-value pairs to it. - The
text_keyspecifies which key in thedatadictionary should be considered the primary text content. Thedefault_valueprovides a fallback if thetext_keyis not present. - The
Dataobject is also convenient for visualization of outputs, since the output preview has visual elements to inspect data as a table and its cells as pop-ups for basic types. The idea is to create a unified way to work and visualize complex information in LLM Controls. - To receive
Dataobjects in a component input, use theDataInputinput type.
Message object
TheMessage object extends the functionality of Data and includes additional attributes and methods for chat interactions.
- Core message data:
text: The main text content of the messagesender: Identifier for the sender (“User” or “AI”)sender_name: Name of the sendersession_id: Identifier for the chat session (stringorUUID)timestamp: Timestamp when the message was created (UTC)flow_id: Identifier for the flow (stringorUUID)id: Unique identifier for the message
- Content and files:
files: List of files or images associated with the messagecontent_blocks: List of structured content block objectsproperties: Additional properties, including visual styling and source information
- Message state:
error: Boolean indicating if there was an erroredit: Boolean indicating if the message was editedcategory: Message category (“message”, “error”, “warning”, “info”)
The
Message object can be used to send, store, and manipulate chat messages within LLM Controls.Create a Message object
You can create aMessage object by directly assigning key-value pairs to it.
To receive Message objects in a component input, you can use the MessageInput input type or MessageTextInput when the goal is to extract just the text field of the Message object.
ContentBlock object
TheContentBlock object is a list of multiple ContentTypes. It allows you to include multiple types of content within a single Message, including images, videos, and text.
Each content type has specific fields related to its data type. For example:
TextContenthas atextfield for storing strings of textMediaContenthas aurlsfield for storing media file URLsCodeContenthascodeandlanguagefields for code snippetsJSONContenthas adatafield for storing arbitrary JSON dataToolContenthas atool_inputfield for storing input parameters for the tool
Create a ContentBlock object
Create aContentBlock object with a list of different content types.
Add ContentBlocks objects to a message
In this example, a text and a mediaContentBlock are added to a message.
DataFrame object
TheDataFrame class is a custom extension of the Pandas DataFrame class, specifically designed to work seamlessly with LLM Controls’ Data objects. The class includes methods for converting between DataFrame and lists of Data objects.
A DataFrame object accepts various input formats, including lists of Data objects, dictionaries, and existing DataFrames.
Create a DataFrame object
You can create a DataFrame object using different data formatsKey Methods
- to_data_list(): Converts the DataFrame back to a list of Data objects.
- add_row(data): Adds a single row (either a Data object or a dictionary) to the DataFrame.
- add_rows(data): Adds multiple rows (list of Data objects or dictionaries) to the DataFrame.