10 implementations of IChatClient
Microsoft.Extensions.AI.Abstractions (1)
Microsoft.Extensions.AI.Abstractions.Tests (1)
Microsoft.Extensions.AI.AzureAIInference (1)
Microsoft.Extensions.AI.Evaluation.Safety (1)
Microsoft.Extensions.AI.Integration.Tests (1)
Microsoft.Extensions.AI.Ollama (1)
Microsoft.Extensions.AI.OpenAI (2)
Microsoft.Extensions.AI.Tests (1)
Microsoft.ML.GenAI.Core (1)
388 references to IChatClient
Aspire.Azure.AI.OpenAI.Tests (23)
Aspire.OpenAI (8)
Aspire.OpenAI.Tests (23)
Microsoft.Extensions.AI (95)
ChatCompletion\AnonymousDelegatingChatClient.cs (6)
23private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? _getResponseFunc;
31private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? _getStreamingResponseFunc;
52IChatClient innerClient,
78IChatClient innerClient,
79Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? getResponseFunc,
80Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? getStreamingResponseFunc)
ChatCompletion\ChatClientBuilder.cs (34)
12/// <summary>A builder for creating pipelines of <see cref="IChatClient"/>.</summary>
15private readonly Func<IServiceProvider, IChatClient> _innerClientFactory;
18private List<Func<IChatClient, IServiceProvider, IChatClient>>? _clientFactories;
21/// <param name="innerClient">The inner <see cref="IChatClient"/> that represents the underlying backend.</param>
23public ChatClientBuilder(IChatClient innerClient)
30/// <param name="innerClientFactory">A callback that produces the inner <see cref="IChatClient"/> that represents the underlying backend.</param>
31public ChatClientBuilder(Func<IServiceProvider, IChatClient> innerClientFactory)
36/// <summary>Builds an <see cref="IChatClient"/> that represents the entire pipeline. Calls to this instance will pass through each of the pipeline stages in turn.</summary>
38/// The <see cref="IServiceProvider"/> that should provide services to the <see cref="IChatClient"/> instances.
41/// <returns>An instance of <see cref="IChatClient"/> that represents the entire pipeline.</returns>
42public IChatClient Build(IServiceProvider? services = null)
45var chatClient = _innerClientFactory(services);
57$"Ensure that the callbacks passed to {nameof(Use)} return non-null {nameof(IChatClient)} instances.");
69public ChatClientBuilder Use(Func<IChatClient, IChatClient> clientFactory)
80public ChatClientBuilder Use(Func<IChatClient, IServiceProvider, IChatClient> clientFactory)
90/// an implementation for both <see cref="IChatClient.GetResponseAsync"/> and <see cref="IChatClient.GetStreamingResponseAsync"/>.
93/// A delegate that provides the implementation for both <see cref="IChatClient.GetResponseAsync"/> and
94/// <see cref="IChatClient.GetStreamingResponseAsync"/>. This delegate is invoked with the list of chat messages, the chat
114/// an implementation for both <see cref="IChatClient.GetResponseAsync"/> and <see cref="IChatClient.GetStreamingResponseAsync"/>.
117/// A delegate that provides the implementation for <see cref="IChatClient.GetResponseAsync"/>. When <see langword="null"/>,
118/// <paramref name="getStreamingResponseFunc"/> must be non-null, and the implementation of <see cref="IChatClient.GetResponseAsync"/>
122/// A delegate that provides the implementation for <see cref="IChatClient.GetStreamingResponseAsync"/>. When <see langword="null"/>,
123/// <paramref name="getResponseFunc"/> must be non-null, and the implementation of <see cref="IChatClient.GetStreamingResponseAsync"/>
129/// <paramref name="getResponseFunc"/> will provide the implementation of <see cref="IChatClient.GetResponseAsync"/>, and
130/// <paramref name="getStreamingResponseFunc"/> will provide the implementation of <see cref="IChatClient.GetStreamingResponseAsync"/>.
132/// is supplied without <paramref name="getStreamingResponseFunc"/>, the implementation of <see cref="IChatClient.GetStreamingResponseAsync"/>
135/// <see cref="IChatClient.GetResponseAsync"/> will be implemented by combining the updates from <paramref name="getStreamingResponseFunc"/>.
139Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? getResponseFunc,
140Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? getStreamingResponseFunc)
ChatCompletion\ChatClientBuilderServiceCollectionExtensions.cs (15)
10/// <summary>Provides extension methods for registering <see cref="IChatClient"/> with a <see cref="IServiceCollection"/>.</summary>
13/// <summary>Registers a singleton <see cref="IChatClient"/> in the <see cref="IServiceCollection"/>.</summary>
15/// <param name="innerClient">The inner <see cref="IChatClient"/> that represents the underlying backend.</param>
23IChatClient innerClient,
32/// <summary>Registers a singleton <see cref="IChatClient"/> in the <see cref="IServiceCollection"/>.</summary>
34/// <param name="innerClientFactory">A callback that produces the inner <see cref="IChatClient"/> that represents the underlying backend.</param>
42Func<IServiceProvider, IChatClient> innerClientFactory,
49serviceCollection.Add(new ServiceDescriptor(typeof(IChatClient), builder.Build, lifetime));
53/// <summary>Registers a keyed singleton <see cref="IChatClient"/> in the <see cref="IServiceCollection"/>.</summary>
56/// <param name="innerClient">The inner <see cref="IChatClient"/> that represents the underlying backend.</param>
65IChatClient innerClient,
74/// <summary>Registers a keyed singleton <see cref="IChatClient"/> in the <see cref="IServiceCollection"/>.</summary>
77/// <param name="innerClientFactory">A callback that produces the inner <see cref="IChatClient"/> that represents the underlying backend.</param>
86Func<IServiceProvider, IChatClient> innerClientFactory,
93serviceCollection.Add(new ServiceDescriptor(typeof(IChatClient), serviceKey, factory: (services, serviceKey) => builder.Build(services), lifetime));
Microsoft.Extensions.AI.Abstractions (45)
ChatCompletion\ChatClientExtensions.cs (14)
12/// <summary>Provides a collection of static methods for extending <see cref="IChatClient"/> instances.</summary>
15/// <summary>Asks the <see cref="IChatClient"/> for an object of type <typeparamref name="TService"/>.</summary>
22/// The purpose of this method is to allow for the retrieval of strongly typed services that may be provided by the <see cref="IChatClient"/>,
25public static TService? GetService<TService>(this IChatClient client, object? serviceKey = null)
33/// Asks the <see cref="IChatClient"/> for an object of the specified type <paramref name="serviceType"/>
44/// The purpose of this method is to allow for the retrieval of services that are required to be provided by the <see cref="IChatClient"/>,
47public static object GetRequiredService(this IChatClient client, Type serviceType, object? serviceKey = null)
58/// Asks the <see cref="IChatClient"/> for an object of type <typeparamref name="TService"/>
68/// The purpose of this method is to allow for the retrieval of strongly typed services that are required to be provided by the <see cref="IChatClient"/>,
71public static TService GetRequiredService<TService>(this IChatClient client, object? serviceKey = null)
92this IChatClient client,
112this IChatClient client,
132this IChatClient client,
152this IChatClient client,
Microsoft.Extensions.AI.Abstractions.Tests (6)
Microsoft.Extensions.AI.AzureAIInference (5)
Microsoft.Extensions.AI.AzureAIInference.Tests (18)
AzureAIInferenceChatClientTests.cs (17)
43IChatClient chatClient = client.AsIChatClient(model);
54IChatClient chatClient = client.AsIChatClient("model");
56Assert.Same(chatClient, chatClient.GetService<IChatClient>());
59using IChatClient pipeline = chatClient
73Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
128using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
201using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
270using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
318using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
354using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
412using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
509using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
592using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
655using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
774using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
860using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
891private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Evaluation (13)
Microsoft.Extensions.AI.Evaluation.Integration.Tests (7)
Microsoft.Extensions.AI.Evaluation.Quality (2)
Microsoft.Extensions.AI.Evaluation.Reporting (10)
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (1)
Microsoft.Extensions.AI.Evaluation.Safety (10)
Microsoft.Extensions.AI.Integration.Tests (7)
Microsoft.Extensions.AI.Ollama (2)
Microsoft.Extensions.AI.Ollama.Tests (12)
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (1)
Microsoft.Extensions.AI.OpenAI (13)
Microsoft.Extensions.AI.OpenAI.Tests (31)
OpenAIChatClientTests.cs (21)
43IChatClient chatClient = client.GetChatClient(model).AsIChatClient();
60IChatClient chatClient = openAIClient.AsIChatClient();
62Assert.Same(chatClient, chatClient.GetService<IChatClient>());
68using IChatClient pipeline = chatClient
81Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
88IChatClient chatClient = openAIClient.AsIChatClient();
90Assert.Same(chatClient, chatClient.GetService<IChatClient>());
93using IChatClient pipeline = chatClient
106Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
156using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
237using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
318using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
407using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
517using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
616using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
739using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
826using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
929using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1071using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1194using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1239private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Tests (56)