Del via


ChatClientBuilder.Use Method

Definition

Overloads

Use(AnonymousDelegatingChatClient+GetResponseSharedFunc)

Adds to the chat client pipeline an anonymous delegating chat client based on a delegate that provides an implementation for both GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) and GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken).

Use(Func<IChatClient,IChatClient>)

Adds a factory for an intermediate chat client to the chat client pipeline.

Use(Func<IChatClient,IServiceProvider,IChatClient>)

Adds a factory for an intermediate chat client to the chat client pipeline.

Use(Func<IList<ChatMessage>,ChatOptions,IChatClient,CancellationToken, Task<ChatResponse>>, Func<IList<ChatMessage>,ChatOptions,IChatClient, CancellationToken,IAsyncEnumerable<ChatResponseUpdate>>)

Adds to the chat client pipeline an anonymous delegating chat client based on a delegate that provides an implementation for both GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) and GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken).

Use(AnonymousDelegatingChatClient+GetResponseSharedFunc)

Adds to the chat client pipeline an anonymous delegating chat client based on a delegate that provides an implementation for both GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) and GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken).

public:
 Microsoft::Extensions::AI::ChatClientBuilder ^ Use(Microsoft::Extensions::AI::AnonymousDelegatingChatClient::GetResponseSharedFunc ^ sharedFunc);
public Microsoft.Extensions.AI.ChatClientBuilder Use(Microsoft.Extensions.AI.AnonymousDelegatingChatClient.GetResponseSharedFunc sharedFunc);
member this.Use : Microsoft.Extensions.AI.AnonymousDelegatingChatClient.GetResponseSharedFunc -> Microsoft.Extensions.AI.ChatClientBuilder
Public Function Use (sharedFunc As AnonymousDelegatingChatClient.GetResponseSharedFunc) As ChatClientBuilder

Parameters

sharedFunc
AnonymousDelegatingChatClient.GetResponseSharedFunc

A delegate that provides the implementation for both GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) and GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken). In addition to the arguments for the operation, it's provided with a delegate to the inner client that should be used to perform the operation on the inner client. It will handle both the non-streaming and streaming cases.

Returns

The updated ChatClientBuilder instance.

Exceptions

sharedFunc is null.

Remarks

This overload may be used when the anonymous implementation needs to provide pre- and/or post-processing, but doesn't need to interact with the results of the operation, which will come from the inner client.

Applies to

Use(Func<IChatClient,IChatClient>)

Source:
ChatClientBuilder.cs

Adds a factory for an intermediate chat client to the chat client pipeline.

public:
 Microsoft::Extensions::AI::ChatClientBuilder ^ Use(Func<Microsoft::Extensions::AI::IChatClient ^, Microsoft::Extensions::AI::IChatClient ^> ^ clientFactory);
public Microsoft.Extensions.AI.ChatClientBuilder Use(Func<Microsoft.Extensions.AI.IChatClient,Microsoft.Extensions.AI.IChatClient> clientFactory);
member this.Use : Func<Microsoft.Extensions.AI.IChatClient, Microsoft.Extensions.AI.IChatClient> -> Microsoft.Extensions.AI.ChatClientBuilder
Public Function Use (clientFactory As Func(Of IChatClient, IChatClient)) As ChatClientBuilder

Parameters

clientFactory
Func<IChatClient,IChatClient>

The client factory function.

Returns

The updated ChatClientBuilder instance.

Applies to

Use(Func<IChatClient,IServiceProvider,IChatClient>)

Source:
ChatClientBuilder.cs

Adds a factory for an intermediate chat client to the chat client pipeline.

public:
 Microsoft::Extensions::AI::ChatClientBuilder ^ Use(Func<Microsoft::Extensions::AI::IChatClient ^, IServiceProvider ^, Microsoft::Extensions::AI::IChatClient ^> ^ clientFactory);
public Microsoft.Extensions.AI.ChatClientBuilder Use(Func<Microsoft.Extensions.AI.IChatClient,IServiceProvider,Microsoft.Extensions.AI.IChatClient> clientFactory);
member this.Use : Func<Microsoft.Extensions.AI.IChatClient, IServiceProvider, Microsoft.Extensions.AI.IChatClient> -> Microsoft.Extensions.AI.ChatClientBuilder
Public Function Use (clientFactory As Func(Of IChatClient, IServiceProvider, IChatClient)) As ChatClientBuilder

Parameters

clientFactory
Func<IChatClient,IServiceProvider,IChatClient>

The client factory function.

Returns

The updated ChatClientBuilder instance.

Applies to

Use(Func<IList<ChatMessage>,ChatOptions,IChatClient,CancellationToken, Task<ChatResponse>>, Func<IList<ChatMessage>,ChatOptions,IChatClient, CancellationToken,IAsyncEnumerable<ChatResponseUpdate>>)

Adds to the chat client pipeline an anonymous delegating chat client based on a delegate that provides an implementation for both GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) and GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken).

public:
 Microsoft::Extensions::AI::ChatClientBuilder ^ Use(Func<System::Collections::Generic::IList<Microsoft::Extensions::AI::ChatMessage ^> ^, Microsoft::Extensions::AI::ChatOptions ^, Microsoft::Extensions::AI::IChatClient ^, System::Threading::CancellationToken, System::Threading::Tasks::Task<Microsoft::Extensions::AI::ChatResponse ^> ^> ^ getResponseFunc, Func<System::Collections::Generic::IList<Microsoft::Extensions::AI::ChatMessage ^> ^, Microsoft::Extensions::AI::ChatOptions ^, Microsoft::Extensions::AI::IChatClient ^, System::Threading::CancellationToken, System::Collections::Generic::IAsyncEnumerable<Microsoft::Extensions::AI::ChatResponseUpdate ^> ^> ^ getStreamingResponseFunc);
public Microsoft.Extensions.AI.ChatClientBuilder Use(Func<System.Collections.Generic.IList<Microsoft.Extensions.AI.ChatMessage>,Microsoft.Extensions.AI.ChatOptions?,Microsoft.Extensions.AI.IChatClient,System.Threading.CancellationToken,System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse>>? getResponseFunc, Func<System.Collections.Generic.IList<Microsoft.Extensions.AI.ChatMessage>,Microsoft.Extensions.AI.ChatOptions?,Microsoft.Extensions.AI.IChatClient,System.Threading.CancellationToken,System.Collections.Generic.IAsyncEnumerable<Microsoft.Extensions.AI.ChatResponseUpdate>>? getStreamingResponseFunc);
member this.Use : Func<System.Collections.Generic.IList<Microsoft.Extensions.AI.ChatMessage>, Microsoft.Extensions.AI.ChatOptions, Microsoft.Extensions.AI.IChatClient, System.Threading.CancellationToken, System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse>> * Func<System.Collections.Generic.IList<Microsoft.Extensions.AI.ChatMessage>, Microsoft.Extensions.AI.ChatOptions, Microsoft.Extensions.AI.IChatClient, System.Threading.CancellationToken, System.Collections.Generic.IAsyncEnumerable<Microsoft.Extensions.AI.ChatResponseUpdate>> -> Microsoft.Extensions.AI.ChatClientBuilder
Public Function Use (getResponseFunc As Func(Of IList(Of ChatMessage), ChatOptions, IChatClient, CancellationToken, Task(Of ChatResponse)), getStreamingResponseFunc As Func(Of IList(Of ChatMessage), ChatOptions, IChatClient, CancellationToken, IAsyncEnumerable(Of ChatResponseUpdate))) As ChatClientBuilder

Parameters

getResponseFunc
Func<IList<ChatMessage>,ChatOptions,IChatClient,CancellationToken,Task<ChatResponse>>

A delegate that provides the implementation for GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken). When null, getStreamingResponseFunc must be non-null, and the implementation of GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) will use getStreamingResponseFunc for the implementation.

getStreamingResponseFunc
Func<IList<ChatMessage>,ChatOptions,IChatClient,CancellationToken,IAsyncEnumerable<ChatResponseUpdate>>

A delegate that provides the implementation for GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken). When null, getResponseFunc must be non-null, and the implementation of GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) will use getResponseFunc for the implementation.

Returns

The updated ChatClientBuilder instance.

Exceptions

Both getResponseFunc and getStreamingResponseFunc are null.

Remarks

One or both delegates may be provided. If both are provided, they will be used for their respective methods: getResponseFunc will provide the implementation of GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken), and getStreamingResponseFunc will provide the implementation of GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken). If only one of the delegates is provided, it will be used for both methods. That means that if getResponseFunc is supplied without getStreamingResponseFunc, the implementation of GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) will employ limited streaming, as it will be operating on the batch output produced by getResponseFunc. And if getStreamingResponseFunc is supplied without getResponseFunc, the implementation of GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken) will be implemented by combining the updates from getStreamingResponseFunc.

Applies to