ChatClientBuilder class

Builds a pipeline of chat client middleware.

The pipeline is composed by calling use, useWithServices, useShared, or useDelegates one or more times, then calling build to produce the final ChatClient. Middleware factories are applied in reverse order so that the first call adds the outermost wrapper.

Available extensions
Annotations
  • @Source(name: 'ChatClientBuilder.cs', namespace: 'Microsoft.Extensions.AI', repository: 'dotnet/extensions', path: 'src/Libraries/Microsoft.Extensions.AI/ChatCompletion/', commit: '1f2b533625b22f645708cd5b5aaa77a0f051ef81')

Constructors

ChatClientBuilder(ChatClient innerClient)
Creates a new ChatClientBuilder wrapping innerClient.
ChatClientBuilder.fromFactory(InnerClientFactory innerClientFactory)
Creates a new ChatClientBuilder from a factory function.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build([ServiceProvider? services]) ChatClient
Builds the pipeline and returns the outermost ChatClient.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
use(ChatClientFactory clientFactory) ChatClientBuilder
Adds a middleware factory to the pipeline.
useDelegates(ChatClientResponseHandler? getResponseFunc, ChatClientStreamingResponseHandler? getStreamingResponseFunc) ChatClientBuilder
Adds an anonymous delegating middleware based on one or both delegates.
useFunctionInvocation({ConfigureFunctionInvokingChatClient? configure}) ChatClientBuilder

Available on ChatClientBuilder, provided by the FunctionInvokingChatClientBuilderExtensions extension

Adds a FunctionInvokingChatClient to the pipeline.
useOpenTelemetry({String? modelId, String? system}) ChatClientBuilder

Available on ChatClientBuilder, provided by the OpenTelemetryChatClientBuilderExtensions extension

Adds an OpenTelemetryChatClient to the pipeline.
useShared(ChatClientSharedDelegate sharedFunc) ChatClientBuilder
Adds an anonymous delegating middleware that wraps both operations with a shared callback.
useWithServices(ChatClientFactoryWithServices clientFactory) ChatClientBuilder
Adds a middleware factory to the pipeline.

Operators

operator ==(Object other) bool
The equality operator.
inherited