Κοινή χρήση μέσω


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 completion, 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 may 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)

Initializes a new instance of the FunctionInvokingChatClient class.

Properties

ConcurrentInvocation

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

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 messages in the chat history.

MaximumIterationsPerRequest

Gets or sets the maximum number of iterations per request.

Metadata

Gets metadata that describes the IChatClient.

(Inherited from DelegatingChatClient)
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.

CompleteAsync(IList<ChatMessage>, ChatOptions, CancellationToken)

Sends chat messages to the model and returns the response messages.

CompleteStreamingAsync(IList<ChatMessage>, ChatOptions, CancellationToken)

Sends chat messages to the model and streams the response messages.

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)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetService<TService>(Object)

Asks the IChatClient for an object of type TService.

(Inherited from DelegatingChatClient)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InvokeFunctionAsync(FunctionInvokingChatClient+FunctionInvocationContext, CancellationToken)

Invokes the function asynchronously.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Extension Methods

CompleteAsync(IChatClient, String, ChatOptions, CancellationToken)

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

CompleteStreamingAsync(IChatClient, String, ChatOptions, CancellationToken)

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

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

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

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

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

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

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

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

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

Applies to