FailoverChatClient class abstract
Provides a template for a RoutingChatClient that can select another client after an invocation fails.
The client for each attempt is supplied by selectClient. After an invocation, onRoutingUpdate reports the concrete attempt and whether another selection will follow. An uncanceled failure causes another selection only when it happened before any streaming output was exposed and the attempt limit permits it.
The base class owns invocation, streaming commitment, attempt limits, and attempt reporting. Derived classes own client selection, policy state, selection-failure cleanup, and the lifetime of clients they retain.
Once a streaming response is being listened to, abandoning it without cancellation prevents both inner stream cleanup and the terminal routing update.
Upstream marks the ChatRouting family [Experimental]; the surface
may change as upstream stabilizes.
- Inheritance
-
- Object
- RoutingChatClient
- FailoverChatClient
- Implementers
- Available extensions
- Annotations
-
- @Source(name: 'FailoverChatClient.cs', namespace: 'Microsoft.Extensions.AI', repository: 'dotnet/extensions', path: 'src/Libraries/Microsoft.Extensions.AI/ChatRouting/')
Constructors
- FailoverChatClient()
- Creates a new FailoverChatClient.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- maximumAttemptsPerRequest ↔ int?
-
The maximum number of client invocations permitted for one request.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
asBuilder(
) → ChatClientBuilder -
Available on ChatClient, provided by the ChatClientBuilderChatClientExtensions extension
Creates a new ChatClientBuilder usinginnerClientas its inner client. -
dispose(
) → void -
Performs application-defined tasks associated with freeing, releasing,
or resetting unmanaged resources.
inherited
-
getChatResponseFromMessage(
ChatMessage message, {ChatOptions? options, CancellationToken? cancellationToken}) → Future< ChatResponse> -
Available on ChatClient, provided by the ChatClientExtensions extension
Sends a single message and returns the response. -
getChatResponseFromText(
String message, {ChatOptions? options, CancellationToken? cancellationToken}) → Future< ChatResponse> -
Available on ChatClient, provided by the ChatClientExtensions extension
Sends a single user text message and returns the response. -
getResponse(
{required Iterable< ChatMessage> messages, ChatOptions? options, CancellationToken? cancellationToken}) → Future<ChatResponse> -
Sends a chat request and returns the complete response.
override
-
getService<
T> ({Object? key}) → T? -
Gets a service of the specified type.
inherited
-
getStreamingChatResponseFromMessage(
ChatMessage message, {ChatOptions? options, CancellationToken? cancellationToken}) → Stream< ChatResponseUpdate> -
Available on ChatClient, provided by the ChatClientExtensions extension
Sends a single message and returns a streaming response. -
getStreamingChatResponseFromText(
String message, {ChatOptions? options, CancellationToken? cancellationToken}) → Stream< ChatResponseUpdate> -
Available on ChatClient, provided by the ChatClientExtensions extension
Sends a single user text message and returns a streaming response. -
getStreamingResponse(
{required Iterable< ChatMessage> messages, ChatOptions? options, CancellationToken? cancellationToken}) → Stream<ChatResponseUpdate> -
Sends a chat request and returns a stream of response updates.
override
-
getStructuredResponse<
T> ({required Iterable< ChatMessage> messages, required Map<String, dynamic> schema, required StructuredResultFromJson<T> fromJson, String? schemaName, String? schemaDescription, ChatOptions? options, bool? useJsonSchemaResponseFormat, CancellationToken? cancellationToken}) → Future<StructuredChatResponse< T> > -
Available on ChatClient, provided by the ChatClientStructuredOutputExtensions extension
Sends chat messages, requesting a response matchingschemaand deserialized viafromJson. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onRoutingUpdate(
RoutingContext context, FailoverChatClientAttempt attempt, {required bool isTerminal, CancellationToken? cancellationToken}) → Future< void> - Invoked after a client invocation completes, fails, or is abandoned.
-
selectClient(
RoutingContext context, CancellationToken? cancellationToken) → Future< ChatClient> -
Selects the client to invoke for the request.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited