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.
-
useChatReducer(
ChatReducer reducer) → ChatClientBuilder -
Available on ChatClientBuilder, provided by the ReducingChatClientBuilderExtensions extension
Adds a ReducingChatClient that reduces message history viareducerbefore forwarding each request. -
useConfigureOptions(
ChatOptions configure(ChatOptions options)) → ChatClientBuilder -
Available on ChatClientBuilder, provided by the ConfigureOptionsChatClientBuilderExtensions extension
Adds a callback that configures the ChatOptions passed to each request. -
useDelegates(
ChatClientResponseHandler? getResponseFunc, ChatClientStreamingResponseHandler? getStreamingResponseFunc) → ChatClientBuilder - Adds an anonymous delegating middleware based on one or both delegates.
-
useDistributedCache(
{DistributedCache? storage, required Uint8List serializeResponse(ChatResponse response), required ChatResponse deserializeResponse(Uint8List data), DistributedCacheEntryOptions? cacheOptions, void configure(DistributedCachingChatClient client)?}) → ChatClientBuilder -
Available on ChatClientBuilder, provided by the DistributedCachingChatClientBuilderExtensions extension
Adds response caching backed by a DistributedCache. -
useFunctionInvocation(
{ConfigureFunctionInvokingChatClient? configure}) → ChatClientBuilder -
Available on ChatClientBuilder, provided by the FunctionInvokingChatClientBuilderExtensions extension
Adds a FunctionInvokingChatClient to the pipeline. -
useImageGeneration(
{ImageGenerator? imageGenerator}) → ChatClientBuilder -
Available on ChatClientBuilder, provided by the ImageGeneratingChatClientBuilderExtensions extension
Adds an ImageGeneratingChatClient that fulfills image generation requests usingimageGenerator. -
useLogging(
{LoggerFactory? loggerFactory, ConfigureLoggingChatClient? configure}) → ChatClientBuilder -
Available on ChatClientBuilder, provided by the LoggingChatClientBuilderExtensions extension
-
useOpenTelemetry(
{String? modelId, String? system}) → ChatClientBuilder -
Available on ChatClientBuilder, provided by the OpenTelemetryChatClientBuilderExtensions extension
Adds an OpenTelemetryChatClient to the pipeline. - 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