Condividi tramite


ConfigureOptionsChatClientBuilderExtensions.UseChatOptions Method

Definition

Adds a callback that updates or replaces ChatOptions. This can be used to set default options.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::AI::ChatClientBuilder ^ UseChatOptions(Microsoft::Extensions::AI::ChatClientBuilder ^ builder, Func<Microsoft::Extensions::AI::ChatOptions ^, Microsoft::Extensions::AI::ChatOptions ^> ^ configureOptions);
public static Microsoft.Extensions.AI.ChatClientBuilder UseChatOptions (this Microsoft.Extensions.AI.ChatClientBuilder builder, Func<Microsoft.Extensions.AI.ChatOptions?,Microsoft.Extensions.AI.ChatOptions?> configureOptions);
static member UseChatOptions : Microsoft.Extensions.AI.ChatClientBuilder * Func<Microsoft.Extensions.AI.ChatOptions, Microsoft.Extensions.AI.ChatOptions> -> Microsoft.Extensions.AI.ChatClientBuilder
<Extension()>
Public Function UseChatOptions (builder As ChatClientBuilder, configureOptions As Func(Of ChatOptions, ChatOptions)) As ChatClientBuilder

Parameters

configureOptions
Func<ChatOptions,ChatOptions>

The delegate to invoke to configure the ChatOptions instance. It is passed the caller-supplied ChatOptions instance and should return the configured ChatOptions instance to use.

Returns

The builder.

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.

Applies to