RadzenAIChat Class

RadzenAIChat component that provides a modern chat interface with AI integration and conversation memory.

Inheritance

Object

ComponentBase

RadzenComponent

RadzenAIChat

Implements

IComponent

IHandleEvent

IHandleAfterRender

Namespace: Radzen.Blazor

Assembly: Radzen.Blazor.dll

Syntax

public class RadzenAIChat : RadzenComponent, IComponent, IHandleEvent, IHandleAfterRender

Examples

<RadzenAIChat Title="AI Assistant" Placeholder="Type your message..." @bind-Messages="@chatMessages" SessionId="@sessionId" />

Constructors

RadzenAIChatlink

RadzenAIChat component that provides a modern chat interface with AI integration and conversation memory.

Declaration
public RadzenAIChat()

Properties

ApiKeylink

Gets or sets the API key for authentication.

Declaration
public string ApiKey { get; set; }
Property Value
Type Description
stringGets or sets the API key for authentication.

ApiKeyHeaderlink

Gets or sets the API key header name.

Declaration
public string ApiKeyHeader { get; set; }
Property Value
Type Description
stringGets or sets the API key header name.

AssistantAvatarTextlink

Gets or sets the text displayed in the assistant avatar.

Declaration
public string AssistantAvatarText { get; set; }
Property Value
Type Description
stringGets or sets the text displayed in the assistant avatar.

ChatClearedlink

Event callback that is invoked when the chat is cleared.

Declaration
public EventCallback ChatCleared { get; set; }
Property Value
Type Description
EventCallbackEvent callback that is invoked when the chat is cleared.

Disabledlink

Gets or sets whether the chat is disabled.

Declaration
public bool Disabled { get; set; }
Property Value
Type Description
boolGets or sets whether the chat is disabled.

EmptyMessagelink

Gets or sets the message displayed when there are no messages.

Declaration
public string EmptyMessage { get; set; }
Property Value
Type Description
stringGets or sets the message displayed when there are no messages.

EmptyTemplatelink

Gets or sets the empty template shown when there are no messages.

Declaration
public RenderFragment EmptyTemplate { get; set; }
Property Value
Type Description
RenderFragmentGets or sets the empty template shown when there are no messages.

Endpointlink

Gets or sets the endpoint URL for the AI service.

Declaration
public string Endpoint { get; set; }
Property Value
Type Description
stringGets or sets the endpoint URL for the AI service.

InputAttributeslink

Specifies additional custom attributes that will be rendered by the input.

Declaration
public IReadOnlyDictionary<string, object> InputAttributes { get; set; }
Property Value
Type Description
IReadOnlyDictionary<string, object>Specifies additional custom attributes that will be rendered by the input.

MaxMessageslink

Gets or sets the maximum number of messages to keep in the chat.

Declaration
public int MaxMessages { get; set; }
Property Value
Type Description
intGets or sets the maximum number of messages to keep in the chat.

MaxTokenslink

Gets or sets the max tokens.

Declaration
public int? MaxTokens { get; set; }
Property Value
Type Description
int?Gets or sets the max tokens.

MessageAddedlink

Event callback that is invoked when a new message is added.

Declaration
public EventCallback<ChatMessage> MessageAdded { get; set; }
Property Value
Type Description
EventCallback<ChatMessage>Event callback that is invoked when a new message is added.

MessageSentlink

Event callback that is invoked when a message is sent.

Declaration
public EventCallback<string> MessageSent { get; set; }
Property Value
Type Description
EventCallback<string>Event callback that is invoked when a message is sent.

MessageTemplatelink

Gets or sets the message template.

Declaration
public RenderFragment<ChatMessage> MessageTemplate { get; set; }
Property Value
Type Description
RenderFragment<ChatMessage>Gets or sets the message template.

Modellink

Gets or sets the model name.

Declaration
public string Model { get; set; }
Property Value
Type Description
stringGets or sets the model name.

Placeholderlink

Gets or sets the placeholder text for the input field.

Declaration
public string Placeholder { get; set; }
Property Value
Type Description
stringGets or sets the placeholder text for the input field.

Proxylink

Gets or sets the proxy URL for the AI service.

Declaration
public string Proxy { get; set; }
Property Value
Type Description
stringGets or sets the proxy URL for the AI service.

ReadOnlylink

Gets or sets whether the input is read-only.

Declaration
public bool ReadOnly { get; set; }
Property Value
Type Description
boolGets or sets whether the input is read-only.

ResponseReceivedlink

Event callback that is invoked when the AI response is received.

Declaration
public EventCallback<string> ResponseReceived { get; set; }
Property Value
Type Description
EventCallback<string>Event callback that is invoked when the AI response is received.

SessionIdlink

Gets or sets the session ID for maintaining conversation memory. If null, a new session will be created.

Declaration
public string SessionId { get; set; }
Property Value
Type Description
stringGets or sets the session ID for maintaining conversation memory. If null, a new session will be created.

SessionIdChangedlink

Event callback that is invoked when a session ID is created or retrieved.

Declaration
public EventCallback<string> SessionIdChanged { get; set; }
Property Value
Type Description
EventCallback<string>Event callback that is invoked when a session ID is created or retrieved.

ShowClearButtonlink

Gets or sets whether to show the clear chat button.

Declaration
public bool ShowClearButton { get; set; }
Property Value
Type Description
boolGets or sets whether to show the clear chat button.

SystemPromptlink

Gets or sets the system prompt.

Declaration
public string SystemPrompt { get; set; }
Property Value
Type Description
stringGets or sets the system prompt.

Temperaturelink

Gets or sets the temperature.

Declaration
public double? Temperature { get; set; }
Property Value
Type Description
double?Gets or sets the temperature.

Titlelink

Gets or sets the title displayed in the chat header.

Declaration
public string Title { get; set; }
Property Value
Type Description
stringGets or sets the title displayed in the chat header.

UserAvatarTextlink

Gets or sets the text displayed in the user avatar.

Declaration
public string UserAvatarText { get; set; }
Property Value
Type Description
stringGets or sets the text displayed in the user avatar.

Methods

AddMessagelink

Adds a message to the chat.

Declaration
public ChatMessage AddMessage(string content, bool isUser)
Parameters
Type Name Description
string content The message content.
bool isUser Whether the message is from the user.
Returns
Type Description
ChatMessageThe created message.

BuildRenderTreelink

Declaration
protected override void BuildRenderTree(Rendering.RenderTreeBuilder __builder)
Parameters
Type Name Description
Rendering.RenderTreeBuilder __builder

ClearChatlink

Clears all messages from the chat.

Declaration
public Task ClearChat()
Returns
Type Description
Task

Disposelink

Declaration
public override void Dispose()

GetComponentCssClasslink

Declaration
protected override string GetComponentCssClass()
Returns
Type Description
string

GetMessageslink

Gets the current list of messages.

Declaration
public IReadOnlyList<ChatMessage> GetMessages()
Returns
Type Description
IReadOnlyList<ChatMessage>

GetSessionIdlink

Gets the current session ID.

Declaration
public string GetSessionId()
Returns
Type Description
string

LoadConversationHistorylink

Loads conversation history from the AI service session.

Declaration
public Task LoadConversationHistory()
Returns
Type Description
Task

OnAfterRenderAsynclink

Declaration
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
Type Name Description
bool firstRender
Returns
Type Description
Task

OnInitializedAsynclink

Declaration
protected override Task OnInitializedAsync()
Returns
Type Description
Task

OnParametersSetAsynclink

Declaration
protected override Task OnParametersSetAsync()
Returns
Type Description
Task

SendMessagelink

Sends a message programmatically.

Declaration
public Task SendMessage(string content)
Parameters
Type Name Description
string content The message content to send.
Returns
Type Description
Task

SendMessagelink

Sends a message programmatically.

Declaration
public Task SendMessage(string content, string model, string systemPrompt, double? temperature, int? maxTokens, string endpoint, string proxy, string apiKey, string apiKeyHeader)
Parameters
Type Name Description
string content The message content to send.
string model
string systemPrompt
double? temperature
int? maxTokens
string endpoint
string proxy
string apiKey
string apiKeyHeader
Returns
Type Description
Task
An error has occurred. This app may no longer respond until reloaded. Reload 🗙