次の方法で共有


FunctionInvokingChatClient Class

Definition

A delegating chat client that invokes functions defined on ChatOptions. Include this in a chat pipeline to resolve function calls automatically.

public ref class FunctionInvokingChatClient : Microsoft::Extensions::AI::DelegatingChatClient
public class FunctionInvokingChatClient : Microsoft.Extensions.AI.DelegatingChatClient
type FunctionInvokingChatClient = class
    inherit DelegatingChatClient
Public Class FunctionInvokingChatClient
Inherits DelegatingChatClient
Inheritance
FunctionInvokingChatClient

Remarks

When this client receives a FunctionCallContent in a chat response, it responds by calling the corresponding AIFunction defined in ChatOptions, producing a FunctionResultContent.

The provided implementation of IChatClient is thread-safe for concurrent use so long as the AIFunction instances employed as part of the supplied ChatOptions are also safe. The ConcurrentInvocation property can be used to control whether multiple function invocation requests as part of the same request are invocable concurrently, but even with that set to false (the default), multiple concurrent requests to this same instance and using the same tools could result in those tools being used concurrently (one per request). For example, a function that accesses the HttpContext of a specific ASP.NET web request should only be used as part of a single ChatOptions at a time, and only with ConcurrentInvocation set to false, in case the inner client decided to issue multiple invocation requests to that same function.

Constructors

FunctionInvokingChatClient(IChatClient, ILogger)

Initializes a new instance of the FunctionInvokingChatClient class.

Properties

ConcurrentInvocation

Gets or sets a value indicating whether to allow concurrent invocation of functions.

CurrentContext

Gets or sets the FunctionInvokingChatClient.FunctionInvocationContext for the current function invocation.

DetailedErrors

Gets or sets a value indicating whether detailed exception information should be included in the chat history when calling the underlying IChatClient.

InnerClient

Gets the inner IChatClient.

(Inherited from DelegatingChatClient)
KeepFunctionCallingMessages

Gets or sets a value indicating whether to keep intermediate function calling request and response messages in the chat history.

MaximumIterationsPerRequest

Gets or sets the maximum number of iterations per request.

RetryOnError

Gets or sets a value indicating whether to handle exceptions that occur during function calls.

Methods

AddResponseMessages(IList<ChatMessage>, ReadOnlySpan<FunctionInvokingChatClient.FunctionInvocationResult>)

Adds one or more response messages for function invocation results.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

(Inherited from DelegatingChatClient)
Dispose(Boolean)

Provides a mechanism for releasing unmanaged resources.

(Inherited from DelegatingChatClient)
GetResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken)

Sends chat messages and returns the response.

GetService(Type, Object)

Asks the IChatClient for an object of the specified type serviceType.

(Inherited from DelegatingChatClient)
GetStreamingResponseAsync(IList<ChatMessage>, ChatOptions, CancellationToken)

Sends chat messages and streams the response.

InvokeFunctionAsync(FunctionInvokingChatClient+FunctionInvocationContext, CancellationToken)

Invokes the function asynchronously.

Extension Methods

AsBuilder(IChatClient)

Creates a new ChatClientBuilder using innerClient as its inner client.

GetResponseAsync(IChatClient, ChatMessage, ChatOptions, CancellationToken)

Sends a chat message and returns the response messages.

GetResponseAsync(IChatClient, String, ChatOptions, CancellationToken)

Sends a user chat text message and returns the response messages.

GetService<TService>(IChatClient, Object)

Asks the IChatClient for an object of type TService.

GetStreamingResponseAsync(IChatClient, ChatMessage, ChatOptions, CancellationToken)

Sends a chat message and streams the response messages.

GetStreamingResponseAsync(IChatClient, String, ChatOptions, CancellationToken)

Sends a user chat text message and streams the response messages.

GetResponseAsync<T>(IChatClient, ChatMessage, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a chat message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, ChatMessage, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a chat message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, IList<ChatMessage>, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends chat messages, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, IList<ChatMessage>, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends chat messages, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, String, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a user chat text message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, String, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a user chat text message, requesting a response matching the type T.

Applies to