9 implementations of IChatClient
Microsoft.Extensions.AI.Abstractions (1)
Microsoft.Extensions.AI.Abstractions.Tests (1)
Microsoft.Extensions.AI.AzureAIInference (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)
361 references to IChatClient
Aspire.Azure.AI.OpenAI.Tests (23)
Aspire.OpenAI (8)
Aspire.OpenAI.Tests (23)
Microsoft.Extensions.AI (96)
ChatCompletion\AnonymousDelegatingChatClient.cs (6)
20private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? _getResponseFunc;
28private readonly Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? _getStreamingResponseFunc;
49IChatClient innerClient,
75IChatClient innerClient,
76Func<IEnumerable<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatResponse>>? getResponseFunc,
77Func<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 (40)
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)
65IChatClient chatClient = client.AsChatClient(model);
76IChatClient chatClient = client.AsChatClient("model");
78Assert.Same(chatClient, chatClient.GetService<IChatClient>());
83using IChatClient pipeline = chatClient
97Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
153using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
225using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
293using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
341using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
377using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
434using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
531using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
613using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
676using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
795using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
881using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
911private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Evaluation (13)
Microsoft.Extensions.AI.Evaluation.Integration.Tests (5)
Microsoft.Extensions.AI.Evaluation.Quality (2)
Microsoft.Extensions.AI.Evaluation.Reporting (12)
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (1)
Microsoft.Extensions.AI.Integration.Tests (7)
Microsoft.Extensions.AI.Ollama (2)
Microsoft.Extensions.AI.Ollama.Tests (12)
Microsoft.Extensions.AI.OpenAI (12)
Microsoft.Extensions.AI.OpenAI.Tests (20)
OpenAIChatClientTests.cs (19)
74IChatClient chatClient = client.AsChatClient(model);
91IChatClient chatClient = openAIClient.AsChatClient("model");
93Assert.Same(chatClient, chatClient.GetService<IChatClient>());
100using IChatClient pipeline = chatClient
113Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
120IChatClient chatClient = openAIClient.AsChatClient();
122Assert.Same(chatClient, chatClient.GetService<IChatClient>());
125using IChatClient pipeline = chatClient
138Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
188using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
268using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
348using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
437using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
546using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
645using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
766using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
869using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1010using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1060private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Tests (56)