Partager via


ConfigureOptionsChatClient Class

Definition

A delegating chat client that updates or replaces the ChatOptions used by the remainder of the pipeline.

public ref class ConfigureOptionsChatClient sealed : Microsoft::Extensions::AI::DelegatingChatClient
public sealed class ConfigureOptionsChatClient : Microsoft.Extensions.AI.DelegatingChatClient
type ConfigureOptionsChatClient = class
    inherit DelegatingChatClient
Public NotInheritable Class ConfigureOptionsChatClient
Inherits DelegatingChatClient
Inheritance
ConfigureOptionsChatClient

Remarks

The configuration callback is invoked with the caller-supplied ChatOptions instance. To override the caller-supplied options with a new instance, the callback may simply return that new instance, for example _ => new ChatOptions() { MaxTokens = 1000 }. To provide a new instance only if the caller-supplied instance is null, the callback may conditionally return a new instance, for example options => options ?? new ChatOptions() { MaxTokens = 1000 }. Any changes to the caller-provided options instance will persist on the original instance, so the callback must take care to only do so when such mutations are acceptable, such as by cloning the original instance and mutating the clone, for example: options => { var newOptions = options?.Clone() ?? new(); newOptions.MaxTokens = 1000; return newOptions; }

The callback may return null, in which case a null options will be passed to the next client in the pipeline.

The provided implementation of IChatClient is thread-safe for concurrent use so long as the employed configuration callback is also thread-safe for concurrent requests. If callers employ a shared options instance, care should be taken in the configuration callback, as multiple calls to it may end up running in parallel with the same options instance.

Constructors

ConfigureOptionsChatClient(IChatClient, Func<ChatOptions,ChatOptions>)

Initializes a new instance of the ConfigureOptionsChatClient class with the specified configureOptions callback.

Properties

InnerClient

Gets the inner IChatClient.

(Inherited from DelegatingChatClient)
Metadata

Gets metadata that describes the IChatClient.

(Inherited from DelegatingChatClient)

Methods

CompleteAsync(IList<ChatMessage>, ChatOptions, CancellationToken)
CompleteStreamingAsync(IList<ChatMessage>, ChatOptions, CancellationToken)
Dispose()

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

(Inherited from DelegatingChatClient)
Dispose(Boolean)

Provides a mechanism for releasing unmanaged resources.

(Inherited from DelegatingChatClient)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetService<TService>(Object)

Asks the IChatClient for an object of type TService.

(Inherited from DelegatingChatClient)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Extension Methods

CompleteAsync(IChatClient, String, ChatOptions, CancellationToken)

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

CompleteStreamingAsync(IChatClient, String, ChatOptions, CancellationToken)

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

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

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

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

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

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

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

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

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

Applies to