RoutingChatClient Class

Definition

Provides a template for an IChatClient that selects and invokes another chat client.

public ref class RoutingChatClient abstract : IDisposable, Microsoft::Extensions::AI::IChatClient
[System.Diagnostics.CodeAnalysis.Experimental("MEAI001", UrlFormat="https://aka.ms/dotnet-extensions-warnings/{0}")]
public abstract class RoutingChatClient : IDisposable, Microsoft.Extensions.AI.IChatClient
[<System.Diagnostics.CodeAnalysis.Experimental("MEAI001", UrlFormat="https://aka.ms/dotnet-extensions-warnings/{0}")>]
type RoutingChatClient = class
    interface IChatClient
    interface IDisposable
Public MustInherit Class RoutingChatClient
Implements IChatClient, IDisposable
Inheritance
RoutingChatClient
Derived
Attributes
Implements

Remarks

Derived classes implement SelectClientAsync(RoutingContext, CancellationToken) to supply one client for each request. The selected client is invoked once, and its response or failure is propagated to the caller. The exact client instance represents the selected routing identity. Caller-supplied options may vary per invocation, but they are ephemeral and do not participate in that identity. Applications can use distinct configured client wrappers when configurations require distinct routing identities, while custom policies may maintain separate application-specific grouping keys.

ChatOptions holds the options for the request and is what the selected client receives. Options that belong to a particular route are configured on the client instead, typically with a ConfigureOptionsChatClient wrapper, which clones the request options and applies the route's own values on top of them.

Constructors

Name Description
RoutingChatClient()

Methods

Name Description
Create(Func<RoutingContext,CancellationToken,ValueTask<IChatClient>>)

Creates a routing client that selects one client for each request.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Dispose(Boolean)

Provides a mechanism for releasing resources owned by the derived instance.

GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken)

Sends chat messages and returns the response.

GetService(Type, Object)

Asks the IChatClient for an object of the specified type serviceType.

GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken)

Sends chat messages and streams the response.

SelectClientAsync(RoutingContext, CancellationToken)

Selects the client to invoke for the request.

Extension Methods

Name Description
AsBuilder(IChatClient)

Creates a new ChatClientBuilder using innerClient as its inner client.

GetRequiredService(IChatClient, Type, Object)

Asks the IChatClient for an object of the specified type serviceType and throws an exception if one isn't available.

GetRequiredService<TService>(IChatClient, Object)

Asks the IChatClient for an object of type TService and throws an exception if one isn't available.

GetResponseAsync(IChatClient, ChatMessage, ChatOptions, CancellationToken)

Sends a chat message and returns the response messages.

GetResponseAsync(IChatClient, String, ChatOptions, CancellationToken)

Sends a user chat text message and returns the response messages.

GetResponseAsync<T>(IChatClient, ChatMessage, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a chat message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, ChatMessage, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a chat message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends chat messages, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends chat messages, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, String, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a user chat text message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, String, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a user chat text message, requesting a response matching the type T.

GetService<TService>(IChatClient, Object)

Asks the IChatClient for an object of type TService.

GetStreamingResponseAsync(IChatClient, ChatMessage, ChatOptions, CancellationToken)

Sends a chat message and streams the response messages.

GetStreamingResponseAsync(IChatClient, String, ChatOptions, CancellationToken)

Sends a user chat text message and streams the response messages.

Applies to