7 implementations of IChatClient
Microsoft.Extensions.AI.Abstractions (1)
ChatCompletion\DelegatingChatClient.cs (1)
19public class DelegatingChatClient : IChatClient
Microsoft.Extensions.AI.Abstractions.Tests (1)
TestChatClient.cs (1)
11public sealed class TestChatClient : IChatClient
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
24public sealed partial class AzureAIInferenceChatClient : IChatClient
Microsoft.Extensions.AI.Integration.Tests (1)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (1)
11public sealed class TestChatClient : IChatClient
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
22public sealed class OllamaChatClient : IChatClient
Microsoft.Extensions.AI.OpenAI (1)
OpenAIChatClient.cs (1)
25public sealed partial class OpenAIChatClient : IChatClient
Microsoft.Extensions.AI.Tests (1)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (1)
11public sealed class TestChatClient : IChatClient
157 references to IChatClient
Microsoft.Extensions.AI (52)
ChatCompletion\CachingChatClient.cs (6)
21/// <param name="innerClient">The underlying <see cref="IChatClient"/>.</param> 22protected CachingChatClient(IChatClient innerClient) 203/// This is used when there is a call to <see cref="IChatClient.CompleteAsync(IList{ChatMessage}, ChatOptions?, CancellationToken)"/>. 212/// This is used when there is a call to <see cref="IChatClient.CompleteStreamingAsync(IList{ChatMessage}, ChatOptions?, CancellationToken)"/>. 221/// This is used when there is a call to <see cref="IChatClient.CompleteAsync(IList{ChatMessage}, ChatOptions?, CancellationToken)"/>. 231/// This is used when there is a call to <see cref="IChatClient.CompleteStreamingAsync(IList{ChatMessage}, ChatOptions?, CancellationToken)"/>.
ChatCompletion\ChatClientBuilder.cs (13)
10/// <summary>A builder for creating pipelines of <see cref="IChatClient"/>.</summary> 14private List<Func<IServiceProvider, IChatClient, IChatClient>>? _clientFactories; 26/// <summary>Completes the pipeline by adding a final <see cref="IChatClient"/> that represents the underlying backend. This is typically a client for an LLM service.</summary> 28/// <returns>An instance of <see cref="IChatClient"/> that represents the entire pipeline. Calls to this instance will pass through each of the pipeline stages in turn.</returns> 29public IChatClient Use(IChatClient innerClient) 31var chatClient = Throw.IfNull(innerClient); 41$"Ensure that the callbacks passed to {nameof(Use)} return non-null {nameof(IChatClient)} instances."); 51public ChatClientBuilder Use(Func<IChatClient, IChatClient> clientFactory) 61public ChatClientBuilder Use(Func<IServiceProvider, IChatClient, IChatClient> clientFactory)
ChatCompletion\ChatClientBuilderServiceCollectionExtensions.cs (5)
10/// <summary>Provides extension methods for registering <see cref="IChatClient"/> with a <see cref="IServiceCollection"/>.</summary> 15/// <param name="clientFactory">The factory to use to construct the <see cref="IChatClient"/> instance.</param> 20Func<ChatClientBuilder, IChatClient> clientFactory) 32/// <param name="clientFactory">The factory to use to construct the <see cref="IChatClient"/> instance.</param> 38Func<ChatClientBuilder, IChatClient> clientFactory)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (9)
15/// Provides extension methods on <see cref="IChatClient"/> that simplify working with structured output. 27/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 43this IChatClient chatClient, 52/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 64this IChatClient chatClient, 73/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 86this IChatClient chatClient, 96/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 113this IChatClient chatClient,
ChatCompletion\ConfigureOptionsChatClient.cs (2)
34/// The provided implementation of <see cref="IChatClient"/> is thread-safe for concurrent use so long as the employed configuration 50public ConfigureOptionsChatClient(IChatClient innerClient, Func<ChatOptions?, ChatOptions> configureOptions)
ChatCompletion\DistributedCachingChatClient.cs (3)
17/// The provided implementation of <see cref="IChatClient"/> is thread-safe for concurrent use so long as the employed 26/// <param name="innerClient">The underlying <see cref="IChatClient"/>.</param> 28public DistributedCachingChatClient(IChatClient innerClient, IDistributedCache storage)
ChatCompletion\DistributedCachingChatClientBuilderExtensions.cs (1)
12/// Extension methods for adding a <see cref="DistributedCachingChatClient"/> to an <see cref="IChatClient"/> pipeline.
ChatCompletion\FunctionInvokingChatClient.cs (8)
26/// The provided implementation of <see cref="IChatClient"/> is thread-safe for concurrent use so long as the 45/// <param name="innerClient">The underlying <see cref="IChatClient"/>, or the next instance in a chain of clients.</param> 46public FunctionInvokingChatClient(IChatClient innerClient) 57/// underlying <see cref="IChatClient"/> will be instructed to give a response without invoking 61/// If the value is <see langword="true"/>, the underlying <see cref="IChatClient"/> will be allowed 76/// in the chat history when calling the underlying <see cref="IChatClient"/>. 88/// when calling the underlying <see cref="IChatClient"/>. This can help it to bypass problems on 120/// When the inner <see cref="IChatClient"/> returns <see cref="FunctionCallContent"/> to the
ChatCompletion\LoggingChatClient.cs (3)
17/// The provided implementation of <see cref="IChatClient"/> is thread-safe for concurrent use so long as the 29/// <param name="innerClient">The underlying <see cref="IChatClient"/>.</param> 31public LoggingChatClient(IChatClient innerClient, ILogger logger)
ChatCompletion\OpenTelemetryChatClient.cs (2)
46/// <param name="innerClient">The underlying <see cref="IChatClient"/>.</param> 49public OpenTelemetryChatClient(IChatClient innerClient, ILogger? logger = null, string? sourceName = null)
Microsoft.Extensions.AI.Abstractions (21)
ChatCompletion\AutoChatToolMode.cs (1)
9/// Indicates that an <see cref="IChatClient"/> is free to select any of the available tools, or none at all.
ChatCompletion\ChatClientExtensions.cs (3)
11/// <summary>Provides a collection of static methods for extending <see cref="IChatClient"/> instances.</summary> 21this IChatClient client, 39this IChatClient client,
ChatCompletion\ChatClientMetadata.cs (1)
8/// <summary>Provides metadata about an <see cref="IChatClient"/>.</summary>
ChatCompletion\ChatMessage.cs (1)
12/// <summary>Represents a chat message used by an <see cref="IChatClient" />.</summary>
ChatCompletion\ChatToolMode.cs (2)
9/// Describes how tools should be selected by a <see cref="IChatClient"/>. 33/// instances, and the <see cref="IChatClient"/> is free to invoke zero or more of them.
ChatCompletion\DelegatingChatClient.cs (5)
13/// Provides an optional base class for an <see cref="IChatClient"/> that passes through calls to another instance. 16/// This is recommended as a base type when building clients that can be chained in any order around an underlying <see cref="IChatClient"/>. 25protected DelegatingChatClient(IChatClient innerClient) 37/// <summary>Gets the inner <see cref="IChatClient" />.</summary> 38protected IChatClient InnerClient { get; }
ChatCompletion\IChatClient.cs (7)
14/// Unless otherwise specified, all members of <see cref="IChatClient"/> are thread-safe for concurrent use. 15/// It is expected that all implementations of <see cref="IChatClient"/> support being used by multiple requests concurrently. 18/// However, implementations of <see cref="IChatClient"/> may mutate the arguments supplied to <see cref="CompleteAsync"/> and 21/// invocations or should otherwise ensure by construction that no <see cref="IChatClient"/> instances are used which might employ 56/// <summary>Gets metadata that describes the <see cref="IChatClient"/>.</summary> 59/// <summary>Asks the <see cref="IChatClient"/> for an object of type <typeparamref name="TService"/>.</summary> 64/// The purpose of this method is to allow for the retrieval of strongly-typed services that may be provided by the <see cref="IChatClient"/>,
ChatCompletion\StreamingChatCompletionUpdate.cs (1)
18/// Represents a single response chunk from an <see cref="IChatClient"/>.
Microsoft.Extensions.AI.Abstractions.Tests (2)
ChatCompletion\DelegatingChatClientTests.cs (2)
127var client = delegating.GetService<IChatClient>(expectedKey); 164private sealed class NoOpDelegatingChatClient(IChatClient innerClient)
Microsoft.Extensions.AI.AzureAIInference (4)
AzureAIInferenceChatClient.cs (1)
23/// <summary>An <see cref="IChatClient"/> for an Azure AI Inference <see cref="ChatCompletionsClient"/>.</summary>
AzureAIInferenceExtensions.cs (3)
11/// <summary>Gets an <see cref="IChatClient"/> for use with this <see cref="ChatCompletionsClient"/>.</summary> 14/// <returns>An <see cref="IChatClient"/> that may be used to converse via the <see cref="ChatCompletionsClient"/>.</returns> 15public static IChatClient AsChatClient(this ChatCompletionsClient chatCompletionsClient, string? modelId = null) =>
Microsoft.Extensions.AI.AzureAIInference.Tests (12)
AzureAIInferenceChatClientIntegrationTests.cs (1)
12protected override IChatClient? CreateChatClient() =>
AzureAIInferenceChatClientTests.cs (11)
49IChatClient chatClient = client.AsChatClient(model); 59IChatClient chatClient = client.AsChatClient("model"); 61Assert.Same(chatClient, chatClient.GetService<IChatClient>()); 66using IChatClient pipeline = new ChatClientBuilder() 78Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>()); 123using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 184using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 290using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 409using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 500using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 530private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Integration.Tests (5)
CallCountingChatClient.cs (1)
13internal sealed class CallCountingChatClient(IChatClient innerClient) : DelegatingChatClient(innerClient)
ChatClientIntegrationTests.cs (2)
26private readonly IChatClient? _chatClient; 39protected abstract IChatClient? CreateChatClient();
PromptBasedFunctionCallingChatClient.cs (1)
29internal sealed class PromptBasedFunctionCallingChatClient(IChatClient innerClient)
ReducingChatClientTests.cs (1)
20/// <summary>Provides an example of a custom <see cref="IChatClient"/> for reducing chat message lists.</summary>
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
21/// <summary>An <see cref="IChatClient"/> for Ollama.</summary>
Microsoft.Extensions.AI.Ollama.Tests (10)
OllamaChatClientIntegrationTests.cs (2)
16protected override IChatClient? CreateChatClient() => 92private sealed class AssertNoToolsDefinedChatClient(IChatClient innerClient) : DelegatingChatClient(innerClient)
OllamaChatClientTests.cs (8)
35Assert.Same(client, client.GetService<IChatClient>()); 37using IChatClient pipeline = new ChatClientBuilder() 49Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>()); 58using IChatClient chatClient = new OllamaChatClient(endpoint, model); 155using IChatClient client = new OllamaChatClient(new("http://localhost:11434"), "llama3.1", httpClient); 241using IChatClient client = new OllamaChatClient(new("http://localhost:11434"), httpClient: httpClient); 345using IChatClient client = new OllamaChatClient(new("http://localhost:11434"), "llama3.1", httpClient) 437using IChatClient client = new OllamaChatClient(new("http://localhost:11434"), "llama3.1", httpClient)
Microsoft.Extensions.AI.OpenAI (7)
OpenAIChatClient.cs (1)
24/// <summary>An <see cref="IChatClient"/> for an OpenAI <see cref="OpenAIClient"/> or <see cref="OpenAI.Chat.ChatClient"/>.</summary>
OpenAIClientExtensions.cs (6)
13/// <summary>Gets an <see cref="IChatClient"/> for use with this <see cref="OpenAIClient"/>.</summary> 16/// <returns>An <see cref="IChatClient"/> that may be used to converse via the <see cref="OpenAIClient"/>.</returns> 17public static IChatClient AsChatClient(this OpenAIClient openAIClient, string modelId) => 20/// <summary>Gets an <see cref="IChatClient"/> for use with this <see cref="ChatClient"/>.</summary> 22/// <returns>An <see cref="IChatClient"/> that may be used to converse via the <see cref="ChatClient"/>.</returns> 23public static IChatClient AsChatClient(this ChatClient chatClient) =>
Microsoft.Extensions.AI.OpenAI.Tests (16)
OpenAIChatClientIntegrationTests.cs (1)
10protected override IChatClient? CreateChatClient() =>
OpenAIChatClientTests.cs (15)
60IChatClient chatClient = client.AsChatClient(model); 75IChatClient chatClient = openAIClient.AsChatClient("model"); 77Assert.Same(chatClient, chatClient.GetService<IChatClient>()); 84using IChatClient pipeline = new ChatClientBuilder() 96Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>()); 103IChatClient chatClient = openAIClient.AsChatClient(); 105Assert.Same(chatClient, chatClient.GetService<IChatClient>()); 108using IChatClient pipeline = new ChatClientBuilder() 120Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>()); 165using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 230using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 335using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 455using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 549using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 588private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Tests (27)
ChatCompletion\ChatClientBuilderTest.cs (7)
55Assert.Throws<ArgumentNullException>(() => new ChatClientBuilder().Use((IChatClient)null!)); 62Assert.Throws<ArgumentNullException>(() => builder.Use((Func<IChatClient, IChatClient>)null!)); 63Assert.Throws<ArgumentNullException>(() => builder.Use((Func<IServiceProvider, IChatClient, IChatClient>)null!)); 75private sealed class InnerClientCapturingChatClient(string name, IChatClient innerClient) : DelegatingChatClient(innerClient) 80public new IChatClient InnerClient => base.InnerClient;
ChatCompletion\ConfigureOptionsChatClientTests.cs (2)
38using IChatClient innerClient = new TestChatClient 55using var client = new ChatClientBuilder()
ChatCompletion\DependencyInjectionPatterns.cs (16)
27var instance1 = scope1.ServiceProvider.GetRequiredService<IChatClient>(); 28var instance1Copy = scope1.ServiceProvider.GetRequiredService<IChatClient>(); 29var instance2 = scope2.ServiceProvider.GetRequiredService<IChatClient>(); 58var instance1 = scope1.ServiceProvider.GetRequiredService<IChatClient>(); 59var instance2 = scope2.ServiceProvider.GetRequiredService<IChatClient>(); 87var instance1 = scope1.ServiceProvider.GetRequiredService<IChatClient>(); 88var instance2 = scope2.ServiceProvider.GetRequiredService<IChatClient>(); 97public class ScopedChatClient(IServiceProvider services, IChatClient inner) : DelegatingChatClient(inner) 99public new IChatClient InnerClient => base.InnerClient;
ChatCompletion\FunctionInvokingChatClientTests.cs (1)
287IChatClient service = new ChatClientBuilder().UseFunctionInvocation().Use(innerClient);
ChatCompletion\LoggingChatClientTests.cs (1)
35using IChatClient innerClient = new TestChatClient