Class GenerativeAIChatClient
- Namespace
- GenerativeAI.Microsoft
- Assembly
- GenerativeAI.Microsoft.dll
Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.
public sealed class GenerativeAIChatClient : IChatClient, IDisposable
- Inheritance
-
GenerativeAIChatClient
- Implements
-
IChatClient
- Inherited Members
- Extension Methods
Constructors
GenerativeAIChatClient(IPlatformAdapter, string, bool)
public GenerativeAIChatClient(IPlatformAdapter adapter, string modelName = "models/gemini-3.8-flash", bool autoCallFunction = true)
Parameters
adapterIPlatformAdaptermodelNamestringautoCallFunctionbool
GenerativeAIChatClient(string, string, bool)
public GenerativeAIChatClient(string apiKey, string modelName = "models/gemini-3.8-flash", bool autoCallFunction = true)
Parameters
Properties
AutoCallFunction
Gets or sets a value indicating whether the function calls in the generative AI chat client are automatically invoked without requiring explicit user input. Default: false
public bool AutoCallFunction { get; set; }
Property Value
Remarks
When set to false, the function calls are handled manually, providing flexibility for scenarios where explicit user control over function invocation is required or when using M.E.A.I.'s FunctionInvokingChatClient.
model
Gets the underlying GenerativeModel instance.
public GenerativeModel model { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)
Sends chat messages and returns the response.
public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messagesIEnumerable<ChatMessage>The sequence of chat messages to send.
optionsChatOptionsThe chat options with which to configure the request.
cancellationTokenCancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- Task<ChatResponse>
The response messages generated by the client.
Exceptions
- ArgumentNullException
messagesis null.
GetService(Type, object?)
Asks the Microsoft.Extensions.AI.IChatClient for an object of the specified type serviceType.
public object? GetService(Type serviceType, object? serviceKey = null)
Parameters
serviceTypeTypeThe type of object being requested.
serviceKeyobjectAn optional key that can be used to help identify the target service.
Returns
Remarks
The purpose of this method is to allow for the retrieval of strongly typed services that might be provided by the Microsoft.Extensions.AI.IChatClient, including itself or any services it might be wrapping. For example, to access the Microsoft.Extensions.AI.ChatClientMetadata for the instance, GetService(Type, object) may be used to request it.
Exceptions
- ArgumentNullException
serviceTypeis null.
GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)
Sends chat messages and streams the response.
public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messagesIEnumerable<ChatMessage>The sequence of chat messages to send.
optionsChatOptionsThe chat options with which to configure the request.
cancellationTokenCancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- IAsyncEnumerable<ChatResponseUpdate>
The response messages generated by the client.
Exceptions
- ArgumentNullException
messagesis null.