Compartilhar via


ChatClientBuilder.Use Method

Definition

Overloads

Use(AnonymousDelegatingChatClient+CompleteSharedFunc)

Adds to the chat client pipeline an anonymous delegating chat client based on a delegate that provides an implementation for both CompleteAsync(IList<ChatMessage>, ChatOptions, CancellationToken) and CompleteStreamingAsync(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<ChatCompletion>>, Func<IList<ChatMessage>,ChatOptions,IChatClient, CancellationToken,IAsyncEnumerable<StreamingChatCompletionUpdate>>)

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

Use(AnonymousDelegatingChatClient+CompleteSharedFunc)

Source:
ChatClientBuilder.cs

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

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

Parameters

sharedFunc
AnonymousDelegatingChatClient.CompleteSharedFunc

A delegate that provides the implementation for both CompleteAsync(IList<ChatMessage>, ChatOptions, CancellationToken) and CompleteStreamingAsync(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<ChatCompletion>>, Func<IList<ChatMessage>,ChatOptions,IChatClient, CancellationToken,IAsyncEnumerable<StreamingChatCompletionUpdate>>)

Source:
ChatClientBuilder.cs

Adds to the chat client pipeline an anonymous delegating chat client based on a delegate that provides an implementation for both CompleteAsync(IList<ChatMessage>, ChatOptions, CancellationToken) and CompleteStreamingAsync(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::ChatCompletion ^> ^> ^ completeFunc, 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::StreamingChatCompletionUpdate ^> ^> ^ completeStreamingFunc);
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.ChatCompletion>>? completeFunc, 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.StreamingChatCompletionUpdate>>? completeStreamingFunc);
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.ChatCompletion>> * 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.StreamingChatCompletionUpdate>> -> Microsoft.Extensions.AI.ChatClientBuilder
Public Function Use (completeFunc As Func(Of IList(Of ChatMessage), ChatOptions, IChatClient, CancellationToken, Task(Of ChatCompletion)), completeStreamingFunc As Func(Of IList(Of ChatMessage), ChatOptions, IChatClient, CancellationToken, IAsyncEnumerable(Of StreamingChatCompletionUpdate))) As ChatClientBuilder

Parameters

completeFunc
Func<IList<ChatMessage>,ChatOptions,IChatClient,CancellationToken,Task<ChatCompletion>>

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

completeStreamingFunc
Func<IList<ChatMessage>,ChatOptions,IChatClient,CancellationToken,IAsyncEnumerable<StreamingChatCompletionUpdate>>

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

Returns

The updated ChatClientBuilder instance.

Exceptions

Both completeFunc and completeStreamingFunc are null.

Remarks

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

Applies to