Skip to content

AI

AiMessageActions

Bit.BlazorUI.AI

BitAiMessageActions is the row under a finished assistant message: copy, regenerate (with a session, for the newest reply) and thumbs up or down feedback, plus extra buttons of the app's own, and the metadata the BitAiUiOptions in force choose to show - the model, the token usage, the time. The actions are revealed while the message is hovered or holds the focus; the metadata is always shown. BitAiChatMessage renders one under every reply.

Notes

To use this component, you need to install the Bit.BlazorUI.AI(opens in a new tab) nuget package, as described in the Optional steps of the Getting started page.

Copy and feedback work on the Message alone; regenerate needs the Session that drives it. What the row shows follows the BitAiUiOptions in force: ShowMessageActions for the buttons, ShowModelName, ShowUsage and ShowTimestamps for the metadata (this site turns the model and the usage on). The model is shown by the name the registered model catalog (ai.AddModels) gives it, its id otherwise; the time in the TimeZone of the options, else in the reader's own zone, which the browser is asked for once the row has rendered. The datetime of the time element is the instant itself, in UTC.

The buttons are named for a screen reader and a pressed feedback button says so through aria-pressed, its glyph drawn solid and in the primary color, so the choice is never carried by the color alone. The hidden actions are only faded out: they stay reachable with the keyboard, and they are always shown on a touch screen, on a phone-wide screen, under a preference for more contrast, and when Pinned. A printout keeps the metadata and leaves the buttons out.

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

Give it the Message it belongs to: hover the row, or tab to it, to reveal copy and feedback. The metadata beside them is never hidden: the model and the token usage here, which this site's options turn on (ShowModelName and ShowUsage are off by default; see the Options example).

A finished reply. Hover this row to reveal its actions.
Demo Large138 tokensInput: 42 Output: 96

Pinned

Pinned keeps the actions visible rather than revealing them on hover - for the newest reply, or a row rendered on its own.

A reply whose actions are always shown.
Demo Large138 tokensInput: 42 Output: 96

Feedback

OnFeedback reports the sentiment the user picked - and None when they press the chosen one again to withdraw it. The message's Feedback is already updated, so a host only has to persist it. Under a BitAiChatMessage, a BitAiMessageList or a BitAiChat, the same choice reaches their own OnFeedback as a BitAiMessageFeedback, paired with its message. ShowFeedback takes the thumbs away.

Was this answer helpful?
Demo Large138 tokensInput: 42 Output: 96

Last feedback: None

A reply that does not ask for feedback.
Demo Large138 tokensInput: 42 Output: 96

Regenerate

With a Session, the row offers regenerate, which discards the reply and asks again. Only the newest reply should offer it - regenerating an older one discards everything after it - so CanRegenerate turns it off for the others.

Press regenerate and this reply is written again.
Demo Large138 tokensInput: 42 Output: 96

Extra actions

ExtraActionsTemplate appends buttons of the app's own to the row - a bookmark, here. Draw them like the built-in ones: text buttons with a glyph, a title and an accessible name.

A reply with a bookmark button of the app's own.
Demo Large138 tokensInput: 42 Output: 96

Options

What the row shows is the BitAiUiOptions in force, cascaded by a BitAiOptionsProvider: the first shows the time too, the second only the metadata (ShowMessageActions off).

The model, the usage and the time.
Demo Large138 tokensInput: 42 Output: 96

The metadata alone, without the actions.
Demo Large138 tokensInput: 42 Output: 96

Disabled

A disabled row keeps its metadata and disables its buttons (copy, regenerate, feedback).

A reply whose actions are disabled.
Demo Large138 tokensInput: 42 Output: 96

Cascading parameters

BitParams with a BitAiMessageActionsParams sets what the rows of an app agree on - whether they are pinned, whether they offer feedback, their classes and styles - for every row inside it; a row's own value wins (the second keeps its feedback). Pinned and ShowFeedback reach the rows a BitAiChatMessage renders under its replies too, while their classes and styles come from the message's own Styles / Classes (its MessageActions member).

Pinned, without feedback, from the BitParams around it.
Demo Large138 tokensInput: 42 Output: 96

Pinned from the BitParams, with its own ShowFeedback.
Demo Large138 tokensInput: 42 Output: 96

Style & Class

Style / Class reach the root, Styles / Classes each part (the group of buttons, the regenerate and feedback buttons with the class-styles of BitButton, the model and the time). The public --bit-AiMessageActions-* variables (see the CSS variables table) re-skin it from :root, an ancestor or Style.

Demo Large138 tokensInput: 42 Output: 96

Demo Large138 tokensInput: 42 Output: 96

Demo Large138 tokensInput: 42 Output: 96

RTL

Use BitAiMessageActions in right-to-left (RTL).

پاسخی که دکمه‌هایش همیشه نمایش داده می‌شوند.
Demo Large138 tokensInput: 42 Output: 96

CSS variables

The public custom properties this component reads off its root, for what no parameter covers.

Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property: set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it, or on the Style of one instance to restyle it - and any instance nested inside it, which inherits the value too; a parameter changes one alone, as does the real CSS property on the instance's Style / Styles when that property does not inherit (opacity: 1 keeps one disabled instance undimmed without undimming a disabled one inside it), while an inherited one such as color or font-family also reaches the nested instances that do not set it themselves. Leave a variable unset and the component falls back to the theme token beside it.

BitAiMessageActions CSS variables

Name Default value Description
--bit-AiMessageActions-gap spacing(1.5) Room between the group of actions and each piece of metadata.
--bit-AiMessageActions-actions-gap spacing(0.5) Room between two action buttons.
--bit-AiMessageActions-color var(--bit-clr-fg-ter) Text of the metadata: the model, the usage and the time.
--bit-AiMessageActions-font-size var(--bit-tpg-fs-xs) Size of the metadata.

API

Every parameter, public member, sub-class and enum this component exposes.

BitAiMessageActions parameters

Name Type Default value Description
CanRegenerate bool true Offers regeneration of the message, when a Session is given. Only the newest assistant message should offer it, since regenerating an older one discards everything after it; a BitAiChatMessage sets it from its IsLatest.
Classes BitAiMessageActionsClassStyles? null Custom CSS classes for different parts of the message actions.
ExtraActionsTemplate RenderFragment? null The extra buttons appended to the row of actions, after the feedback buttons. They are revealed and hidden with the built-in ones, and left out with them when the ShowMessageActions of the options in force is off.
Message BitAiMessage The message these actions belong to (required): what copy copies, what feedback is recorded on, and where the model, the usage and the time are read from.
OnFeedback EventCallback<BitAiFeedbackKind> The callback for when the user records feedback, so a host can persist it: Positive or Negative, or None when the user pressed the chosen one again to withdraw it. The message's Feedback is already updated when it is raised. A BitAiChatMessage (and the BitAiMessageList and BitAiChat around it) reports the same choice through its own OnFeedback as a BitAiMessageFeedback, which pairs it with the message (see the BitAiChatMessage page).
Pinned bool false Keeps the actions visible rather than revealing them while the message is hovered or holds the focus.
Session BitAiChatSession? null The session driving the conversation of the message, which enables regeneration.
ShowFeedback bool true Shows the thumbs up and thumbs down buttons.
Styles BitAiMessageActionsClassStyles? null Custom CSS styles for different parts of the message actions.

BitComponentBase parameters

Name Type Default value Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
Disabled bool false Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction.
ForceAnimation bool false Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name.
Id string? null Gets or sets the unique identifier for the component's root element.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.

BitComponentBase public members

Name Type Default value Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.

BitAiMessageActionsClassStyles properties

Name Type Default value Description
Root string? null Custom CSS classes/styles for the root element of the BitAiMessageActions.
Actions string? null Custom CSS classes/styles for the group of action buttons of the BitAiMessageActions.
RegenerateButton BitButtonClassStyles? null Custom CSS classes/styles for the regenerate button of the BitAiMessageActions.
FeedbackButton BitButtonClassStyles? null Custom CSS classes/styles for the two feedback buttons of the BitAiMessageActions.
Model string? null Custom CSS classes/styles for the model name of the BitAiMessageActions.
Time string? null Custom CSS classes/styles for the time of the BitAiMessageActions.

BitAiFeedbackKind enum

Name Value Description
None 0 No feedback given, or the feedback was withdrawn.
Positive 1 The response was helpful (thumbs up).
Negative 2 The response was not helpful (thumbs down).

BitVisibility enum

Name Value Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).

BitDir enum

Name Value Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.