Demos About Radzen
Search Results for

    Show / Hide Table of Contents

    Class AIChatService

    Service for interacting with AI chat models to get completions with conversation memory.

    Inheritance
    object
    AIChatService
    Implements
    IAIChatService
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Radzen
    Assembly: Radzen.Blazor.dll
    Syntax
    public class AIChatService : IAIChatService

    Constructors

    AIChatService(HttpClient, IOptions<AIChatServiceOptions>)

    Service for interacting with AI chat models to get completions with conversation memory.

    Declaration
    public AIChatService(HttpClient httpClient, IOptions<AIChatServiceOptions> options)
    Parameters
    Type Name Description
    HttpClient httpClient
    IOptions<AIChatServiceOptions> options

    Properties

    Options

    Gets the configuration options for the chat streaming service.

    Declaration
    public AIChatServiceOptions Options { get; }
    Property Value
    Type Description
    AIChatServiceOptions

    Methods

    CleanupOldSessions(int)

    Removes old conversation sessions based on age.

    Declaration
    public void CleanupOldSessions(int maxAgeHours = 24)
    Parameters
    Type Name Description
    int maxAgeHours

    Maximum age in hours for sessions to keep.

    ClearSession(string)

    Clears the conversation history for a specific session.

    Declaration
    public void ClearSession(string sessionId)
    Parameters
    Type Name Description
    string sessionId

    The session ID to clear.

    GetActiveSessions()

    Gets all active conversation sessions.

    Declaration
    public IEnumerable<ConversationSession> GetActiveSessions()
    Returns
    Type Description
    IEnumerable<ConversationSession>

    A list of active conversation sessions.

    GetCompletionsAsync(string, string, CancellationToken, string, string, double?, int?)

    Streams chat completion responses from the AI model asynchronously with conversation memory.

    Declaration
    public IAsyncEnumerable<string> GetCompletionsAsync(string userInput, string sessionId = null, CancellationToken cancellationToken = default, string model = null, string systemPrompt = null, double? temperature = null, int? maxTokens = null)
    Parameters
    Type Name Description
    string userInput

    The user's input message to send to the AI model.

    string sessionId

    Optional session ID to maintain conversation context. If null, a new session will be created.

    CancellationToken cancellationToken

    A cancellation token that can be used to cancel the operation.

    string model

    Optional model name to override the configured model.

    string systemPrompt

    Optional system prompt to override the configured system prompt.

    double? temperature

    Optional temperature to override the configured temperature.

    int? maxTokens

    Optional maximum tokens to override the configured max tokens.

    Returns
    Type Description
    IAsyncEnumerable<string>

    An async enumerable that yields streaming response chunks from the AI model.

    GetOrCreateSession(string)

    Gets or creates a conversation session.

    Declaration
    public ConversationSession GetOrCreateSession(string sessionId = null)
    Parameters
    Type Name Description
    string sessionId

    The session ID. If null, a new session will be created.

    Returns
    Type Description
    ConversationSession

    The conversation session.

    Implements

    IAIChatService

    Introducing Radzen Blazor Studio

    Radzen Blazor Studio is a software development environment that empowers developers to design, build and deploy Blazor applications without the traditional hurdles. Write less code and get more done.

    Learn More

    Download Now
    Download Now
    In This Article
    Back to top Radzen Blazor Components, © 2018-2025 Radzen. Source Code licensed under MIT