13 implementations of IChatClient
Microsoft.Extensions.AI.Abstractions (2)
Microsoft.Extensions.AI.Abstractions.Tests (2)
Microsoft.Extensions.AI.Evaluation.Safety (1)
Microsoft.Extensions.AI.Integration.Tests (2)
Microsoft.Extensions.AI.OpenAI (2)
Microsoft.Extensions.AI.Tests (3)
Microsoft.Extensions.DataIngestion.Tests (1)
646 references to IChatClient
Aspire.Azure.AI.Extensions.OpenAI.Tests (31)
Aspire.OpenAI (8)
Aspire.OpenAI.Tests (25)
Microsoft.AspNetCore.Components.AI (16)
Microsoft.Extensions.AI (127)
ChatCompletion\AnonymousDelegatingChatClient.cs (6)
21private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? _getResponseFunc;
29private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? _getStreamingResponseFunc;
50IChatClient innerClient,
76IChatClient innerClient,
77Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? getResponseFunc,
78Func<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.");
70public ChatClientBuilder Use(Func<IChatClient, IChatClient> clientFactory)
82public ChatClientBuilder Use(Func<IChatClient, IServiceProvider, IChatClient> clientFactory)
92/// an implementation for both <see cref="IChatClient.GetResponseAsync"/> and <see cref="IChatClient.GetStreamingResponseAsync"/>.
95/// A delegate that provides the implementation for both <see cref="IChatClient.GetResponseAsync"/> and
96/// <see cref="IChatClient.GetStreamingResponseAsync"/>. This delegate is invoked with the list of chat messages, the chat
117/// an implementation for both <see cref="IChatClient.GetResponseAsync"/> and <see cref="IChatClient.GetStreamingResponseAsync"/>.
120/// A delegate that provides the implementation for <see cref="IChatClient.GetResponseAsync"/>. When <see langword="null"/>,
121/// <paramref name="getStreamingResponseFunc"/> must be non-null, and the implementation of <see cref="IChatClient.GetResponseAsync"/>
125/// A delegate that provides the implementation for <see cref="IChatClient.GetStreamingResponseAsync"/>. When <see langword="null"/>,
126/// <paramref name="getResponseFunc"/> must be non-null, and the implementation of <see cref="IChatClient.GetStreamingResponseAsync"/>
132/// <paramref name="getResponseFunc"/> will provide the implementation of <see cref="IChatClient.GetResponseAsync"/>, and
133/// <paramref name="getStreamingResponseFunc"/> will provide the implementation of <see cref="IChatClient.GetStreamingResponseAsync"/>.
135/// is supplied without <paramref name="getStreamingResponseFunc"/>, the implementation of <see cref="IChatClient.GetStreamingResponseAsync"/>
138/// <see cref="IChatClient.GetResponseAsync"/> will be implemented by combining the updates from <paramref name="getStreamingResponseFunc"/>.
143Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? getResponseFunc,
144Func<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 (71)
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 (12)
Microsoft.Extensions.AI.Evaluation (14)
Microsoft.Extensions.AI.Evaluation.Console (1)
Microsoft.Extensions.AI.Evaluation.Integration.Tests (12)
Microsoft.Extensions.AI.Evaluation.Reporting (13)
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (1)
Microsoft.Extensions.AI.Evaluation.Safety (10)
Microsoft.Extensions.AI.Integration.Tests (24)
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (5)
Microsoft.Extensions.AI.OpenAI (17)
Microsoft.Extensions.AI.OpenAI.Tests (164)
OpenAIChatClientTests.cs (35)
40IChatClient chatClient = client.GetChatClient(model).AsIChatClient();
57IChatClient chatClient = openAIClient.AsIChatClient();
59Assert.Same(chatClient, chatClient.GetService<IChatClient>());
65using IChatClient pipeline = chatClient
78Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
85IChatClient chatClient = openAIClient.AsIChatClient();
87Assert.Same(chatClient, chatClient.GetService<IChatClient>());
90using IChatClient pipeline = chatClient
103Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
153using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
232using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
291using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
362using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
415using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini");
492using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini");
575using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini");
649using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini");
758using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
849using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
956using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1052using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1171using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1256using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1355using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1495using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1620using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1667using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1715using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1761using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1778private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
1900using IChatClient client = CreateChatClient(httpClient, "o4-mini");
1945using IChatClient client = CreateChatClient(httpClient, "gpt-oss-120b");
1995using IChatClient client = CreateChatClient(httpClient, "gpt-oss-120b");
2038using IChatClient client = CreateChatClient(httpClient, "example-model");
2107using IChatClient client = new OpenAIClient(new ApiKeyCredential("apikey"), new OpenAIClientOptions { Transport = new HttpClientPipelineTransport(httpClient) })
OpenAIResponseClientTests.cs (112)
43IChatClient chatClient = client.GetResponsesClient().AsIChatClient(model);
54IChatClient chatClient = openAIClient.AsIChatClient("model");
56Assert.Same(chatClient, chatClient.GetService<IChatClient>());
59using IChatClient pipeline = chatClient
72Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
151using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
294using IChatClient client = CreateResponseClient(httpClient, "o4-mini");
424using IChatClient client = CreateResponseClient(httpClient, "o4-mini");
554using IChatClient client = CreateResponseClient(httpClient, "o4-mini");
656using IChatClient client = CreateResponseClient(httpClient, "o4-mini");
730using IChatClient client = CreateResponseClient(httpClient, "o4-mini");
850using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
990using IChatClient client = CreateResponseClient(httpClient, "computer-use-preview");
1085using IChatClient client = CreateResponseClient(httpClient, "computer-use-preview");
1192using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
1337using IChatClient client = CreateResponseClient(httpClient, modelId: "gpt-4o-mini");
1465using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
1599using (IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini"))
1720using (IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini"))
1859using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2087using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2500using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2707using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2818using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2908using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2980using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3069using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3121using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3216using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
3297using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
3364using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
3488using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
3708using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
3795using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
3864using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3916using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3974using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4033using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4094using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4156using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4219using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4292using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4373using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4444using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4514using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4591using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4669using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4735using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4796using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4866using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4925using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4981using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5042using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5100using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5157using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5216using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5278using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5334using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5389using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5446using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5503using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5540using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5572using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5616using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5669using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5724using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5762using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5797using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5832using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5867using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5905using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5943using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
5963using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6001using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6044using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6087using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6130using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6205using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6277using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6318using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6372using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6435using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
6508using IChatClient client = CreateResponseClient(httpClient, "gpt-4o");
6608using IChatClient client = CreateResponseClient(httpClient, "gpt-4o");
6725using IChatClient client = CreateResponseClient(httpClient, "gpt-4o");
6864using IChatClient client = CreateResponseClient(httpClient, "gpt-4o");
6964using IChatClient client = CreateResponseClient(httpClient, "gpt-4o");
7100using (IChatClient client = CreateResponseClient(httpClient, "gpt-4o"))
7108using (IChatClient client = CreateResponseClient(httpClient, "gpt-4o"))
7190using IChatClient client = CreateResponseClient(httpClient, "o4-mini");
7254using IChatClient client = new OpenAIClient(new ApiKeyCredential("apikey"), new OpenAIClientOptions { Transport = new HttpClientPipelineTransport(httpClient) })
7329using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
7350private static IChatClient CreateResponseClient(HttpClient httpClient, string modelId) =>
7611using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
7738using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
7848using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
7932using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
8024using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8094using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8200using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8301using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8406using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8506using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8593using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8684using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8769using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8882using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
8981using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
9086using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
9199using IChatClient client = CreateResponseClient(httpClient, "gpt-5.4-mini");
9304using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
9397using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
Microsoft.Extensions.AI.Tests (93)
ChatRouting\SemanticRoutingChatClientTests.cs (12)
21var profiles = new Dictionary<IChatClient, IReadOnlyList<string>>(ChatClientReferenceComparer.Instance)
35new Dictionary<IChatClient, IReadOnlyList<string>>(),
40new Dictionary<IChatClient, IReadOnlyList<string>>
48new Dictionary<IChatClient, IReadOnlyList<string>>
107var profiles = new Dictionary<IChatClient, IReadOnlyList<string>>(ChatClientReferenceComparer.Instance)
156var profiles = new Dictionary<IChatClient, IReadOnlyList<string>>(ChatClientReferenceComparer.Instance)
199var profiles = new Dictionary<IChatClient, IReadOnlyList<string>>(ChatClientReferenceComparer.Instance)
223var profiles = new Dictionary<IChatClient, IReadOnlyList<string>>(ChatClientReferenceComparer.Instance)
277private sealed class ChatClientReferenceComparer : IEqualityComparer<IChatClient>
281public bool Equals(IChatClient? x, IChatClient? y) => ReferenceEquals(x, y);
283public int GetHashCode(IChatClient obj) => RuntimeHelpers.GetHashCode(obj);
Microsoft.Extensions.DataIngestion (2)