Skip to content

AI

AiTextPartView

Bit.BlazorUI.AI

BitAiTextPartView renders a text part of a message as Markdown through a BitAiStreamingMarkdown, with a caret while the part is still growing. Citations anchored to character offsets of the part are woven into the text as numbered markers before it is parsed, so each superscript lands mid-sentence where the claim it supports ends - and a citation whose span ends inside code is left to the source list, where a marker cannot break the code.

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.

A chat renders it for every text part of a message (through BitAiMessagePartView) while a chat session appends the deltas its transport streams; render it yourself to show a part anywhere else. It needs the part and the message the part belongs to, whose citations the markers resolve against. It does not listen to the part itself: it renders the part as it stands each time its parent renders it, so whatever appends to a part re-renders its parent - inside a chat that is the BitAiMessagePartView of the part, which follows it; on a page of your own, the page (the Streaming example below does it through a BitAiRenderScheduler). Two of the AI options reach it: InlineCitations (the citation markers) and ShowStreamingCaret (the caret), set for a region with a BitAiOptionsProvider. Model output is untrusted: the Markdown is rendered by a BitAiMarkdownView, which escapes raw HTML and neutralises script URLs (see AiMarkdownView). See it at work in the Streaming and Citations scenarios.

Usage

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

Basic

Part is the BitAiTextPart to render, Message the message it belongs to. A part created with its text is finished; its Markdown is rendered with no caret.

Blazor can render a component in two places:

  • on the server, which streams UI diffs over a circuit;

  • in the browser, on WebAssembly.

Pick per page with @rendermode.

Streaming

A part created empty is streaming: Append adds each delta and Complete finishes it. While it streams a caret trails the text, the last block stays open (a code block is highlighted once its fence closes) and only the tail of the text is parsed again. This one is fed by the scripted Markdown transport of this site (AiDemoTransports.Markdown(), an IBitAiTransport like yours), and the page re-renders through a BitAiRenderScheduler, at most once per 50 ms however fast the deltas arrive.



Citations

A citation of the message anchored to the part (StartIndex / EndIndex of its text, and its PartId - see BitAiCitation) is drawn as a numbered chip where its span ends, numbered as the message numbers it. OnCitationClick is raised when the user activates one. The second citation of this message ends inside a code span, so it gets no marker - a source list under the message still lists it. A span the streamed text has not reached yet gets its marker once it has. BitAiUiOptions.InlineCitations turns the markers off for every part at once (see the Basic example of AiOptionsProvider).

Interactive Server keeps component state on the server and streams UI diffs over a SignalR circuit. Persist what has to survive a dropped circuit with PersistentComponentState.


Activated: none yet

Cascading parameters

BitParams with a BitAiTextPartViewParams sets the look of every text part view inside it - here the Style of the root and the Styles of the Markdown, for the text of a whole region. Inside a chat that reaches the text parts of every message. It is a default, not an override: a view keeps what it sets itself (the last one sets Styles of its own, which replace the cascaded ones).

Blazor can render a component in two places:

  • on the server, which streams UI diffs over a circuit;

  • in the browser, on WebAssembly.

Pick per page with @rendermode.


Interactive Server keeps component state on the server and streams UI diffs over a SignalR circuit. Persist what has to survive a dropped circuit with PersistentComponentState.


Interactive Server keeps component state on the server and streams UI diffs over a SignalR circuit. Persist what has to survive a dropped circuit with PersistentComponentState.

Style & Class

Style and Class reach the root, Styles and Classes its parts: Markdown takes the classes and styles of the BitAiStreamingMarkdown the text is rendered with, and through its own Markdown those of every part of the Markdown view. The text part view publishes no CSS variables of its own: the --bit-AiMarkdownView-* variables restyle its text.

A link, some inline code and bold text.


A link, some inline code and bold text.


A link, some inline code and bold text.


A link, some inline code and bold text.


A link, some inline code and bold text.

RTL

In right-to-left text the Markdown reads from the right - lists, quotes and tables included - whether the direction comes from Dir or from a dir attribute around the part.

بلیزر یک کامپوننت را در دو جا رندر می‌کند:

  • روی سرور، که تغییرات را از راه یک اتصال می‌فرستد؛

  • در مرورگر، روی WebAssembly.

API

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

BitAiTextPartView parameters

Name Type Default value Description
Classes BitAiTextPartViewClassStyles? null Custom CSS classes for different parts of the text part view.
Message BitAiMessage The message the part belongs to (required), whose citations the markers of the text resolve against. Only the citations anchored to this part (their PartId, or none) and whose span the text already reaches are woven in, as numbered markers placed where each span ends; a span that ends inside code gets none.
OnCitationClick EventCallback<BitAiCitation> The callback for when the user activates an inline citation marker, with the citation it stands for.
Part BitAiTextPart The part to render (required) - a BitAiTextPart or a BitAiMarkdownPart. Its text is rendered as Markdown, with a caret and its last block left open while the part is streaming; the citations are woven in again only when the part, its version, the message, the number of its citations or BitAiUiOptions.InlineCitations changed. The view does not subscribe to the part: it shows the part as it stands each time its parent renders it.
Styles BitAiTextPartViewClassStyles? null Custom CSS styles for different parts of the text part view.

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.

BitAiTextPartViewClassStyles properties

Name Type Default value Description
Root string? null Custom CSS classes/styles for the root element of the BitAiTextPartView.
Markdown BitAiStreamingMarkdownClassStyles? null Custom CSS classes/styles for the BitAiStreamingMarkdown the BitAiTextPartView renders its text with (and, through its own Markdown, for every part of the Markdown view inside it).

BitAiTextPart properties

A run of text that grows as the model writes it - the body of an assistant message. new BitAiTextPart() creates an empty part that expects more text (streaming), new BitAiTextPart(text) a finished one, and new BitAiTextPart(text, partId) a part with an identifier a transport addresses it by (null text: streaming). Appending is amortised constant time, and it is safe for one writer and any number of readers. BitAiMarkdownPart is the same part marked as Markdown, for hosts that render plain text parts verbatim; BitAiReasoningPart and BitAiCodePart derive from it too, so they share every member below.

Name Type Default value Description
Text string The text accumulated so far.
Length int 0 How many characters have arrived, without materialising the string - the cheap read for hot paths such as auto-scroll checks.
IsEmpty bool Whether no text has arrived yet.
IsStreaming bool Whether more text is expected: true for a part created without text until Complete is called.
Append(string? delta) void Appends a delta and notifies the observers of the part (an empty delta is ignored).
SetText(string text) void Replaces the whole text, for edits and regenerations.
Complete() void Marks the part finished, which lets the renderers do the work they deferred while it was growing (highlighting a code block, dropping the caret).
Kind string "text" The part kind (BitAiMessagePartKinds.Text; "markdown" for a BitAiMarkdownPart), which picks the renderer of the part in a message.
PartId string The identifier of the part, given to the constructor or generated. An anchored citation names it in its PartId.
Version int 0 Increments on every change, so a renderer compares two integers rather than two texts.
Message BitAiMessage? null The message the part belongs to, once it has been added to one (BitAiMessage.AddPart).
Changed event Action<BitAiMessagePart>? Raised after every change, on whichever thread made it; the message the part belongs to raises its own PartChanged too.

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.