13 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 (3)
Microsoft.Extensions.AI.OpenAI (3)
Microsoft.Extensions.AI.Tests (1)
Microsoft.Extensions.DataIngestion.Tests (1)
Microsoft.ML.GenAI.Core (1)
578 references to IChatClient
Aspire.Azure.AI.Inference (5)
Aspire.Azure.AI.Inference.Tests (8)
Aspire.Azure.AI.OpenAI.Tests (25)
Aspire.Dashboard (5)
Aspire.OpenAI (8)
Aspire.OpenAI.Tests (25)
Microsoft.Extensions.AI (110)
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 (62)
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 (7)
Microsoft.Extensions.AI.AzureAIInference (5)
Microsoft.Extensions.AI.AzureAIInference.Tests (27)
AzureAIInferenceChatClientTests.cs (25)
40IChatClient chatClient = client.AsIChatClient(modelId: null);
57IChatClient chatClient = client.AsIChatClient(model);
68IChatClient chatClient = client.AsIChatClient("model");
70Assert.Same(chatClient, chatClient.GetService<IChatClient>());
73using IChatClient pipeline = chatClient
87Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
142using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
215using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
252using IChatClient client = CreateChatClient(httpClient, modelId: null!);
269using IChatClient client = CreateChatClient(httpClient, modelId: null!);
327using IChatClient client = CreateChatClient(httpClient, modelId: null!);
411using IChatClient client = CreateChatClient(httpClient, modelId: null!);
500using IChatClient client = CreateChatClient(httpClient, modelId: null!);
575using IChatClient client = CreateChatClient(httpClient, modelId: null!);
682using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
741using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
792using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
828using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
885using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
982using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1065using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1128using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1247using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1333using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1364private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
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 (30)
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (5)
Microsoft.Extensions.AI.OpenAI (29)
Microsoft.Extensions.AI.OpenAI.Tests (108)
OpenAIChatClientTests.cs (29)
38IChatClient chatClient = client.GetChatClient(model).AsIChatClient();
55IChatClient chatClient = openAIClient.AsIChatClient();
57Assert.Same(chatClient, chatClient.GetService<IChatClient>());
63using IChatClient pipeline = chatClient
76Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
83IChatClient chatClient = openAIClient.AsIChatClient();
85Assert.Same(chatClient, chatClient.GetService<IChatClient>());
88using IChatClient pipeline = chatClient
101Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
151using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
230using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
328using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
381using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini");
458using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini");
541using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini");
615using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini");
724using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
815using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
922using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1018using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1137using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1221using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1320using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1460using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1580using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1627using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1675using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1721using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1738private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
OpenAIResponseClientTests.cs (67)
42IChatClient chatClient = client.GetOpenAIResponseClient(model).AsIChatClient();
53IChatClient chatClient = openAIClient.AsIChatClient();
55Assert.Same(chatClient, chatClient.GetService<IChatClient>());
58using IChatClient pipeline = chatClient
71Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
150using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
293using IChatClient client = CreateResponseClient(httpClient, "o4-mini");
426using IChatClient client = CreateResponseClient(httpClient, "o4-mini");
557using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
658using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
803using IChatClient client = CreateResponseClient(httpClient, modelId: "gpt-4o-mini");
931using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
1067using (IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini"))
1189using (IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini"))
1435using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
1851using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
1964using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2053using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2105using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2200using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
2281using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
2348using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
2473using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
2693using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-2024-08-06");
2730using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2782using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2840using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2899using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
2960using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3022using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3085using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3158using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3239using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3320using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3398using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3464using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3530using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3600using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3659using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3715using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3776using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3834using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3891using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
3950using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4012using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4068using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4123using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4180using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4237using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4274using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4306using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4350using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4401using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4447using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4482using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4517using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4552using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4590using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4628using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4648using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4686using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4722using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4763using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini");
4828using IChatClient client = CreateResponseClient(httpClient, "gpt-4o");
4929using IChatClient client = CreateResponseClient(httpClient, "gpt-4o");
5047using IChatClient client = CreateResponseClient(httpClient, "gpt-4o");
5124private static IChatClient CreateResponseClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Tests (66)
Microsoft.Extensions.DataIngestion (2)