10 implementations of IChatClient
Microsoft.Extensions.AI.Abstractions (1)
ChatCompletion\DelegatingChatClient.cs (1)
20public 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)
25internal sealed class AzureAIInferenceChatClient : IChatClient
Microsoft.Extensions.AI.Evaluation.Safety (1)
ContentSafetyChatClient.cs (1)
21internal sealed class ContentSafetyChatClient : 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)
24public sealed class OllamaChatClient : IChatClient
Microsoft.Extensions.AI.OpenAI (2)
OpenAIChatClient.cs (1)
26internal sealed partial class OpenAIChatClient : IChatClient
OpenAIResponseChatClient.cs (1)
26internal sealed partial class OpenAIResponseChatClient : IChatClient
Microsoft.Extensions.AI.Tests (1)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (1)
11public sealed class TestChatClient : IChatClient
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
17public abstract class CausalLMPipelineChatClient<TTokenizer, TCausalLMModel> : IChatClient
426 references to IChatClient
Aspire.Azure.AI.Inference (5)
AspireAzureAIInferenceExtensions.cs (5)
157/// Creates a <see cref="IChatClient"/> from the <see cref="ChatCompletionsClient"/> registered in the service collection. 171/// Creates a <see cref="IChatClient"/> from the <see cref="ChatCompletionsClient"/> registered in the service collection. 174/// <param name="serviceKey">The service key with which the <see cref="IChatClient"/> will be registered.</param> 188private static IChatClient CreateInnerChatClient(AspireChatCompletionsClientBuilder builder, IServiceProvider services, string? deploymentId) 194var result = chatCompletionsClient.AsIChatClient(deploymentId ?? builder.DeploymentId);
Aspire.Azure.AI.Inference.Tests (6)
AspireAzureAIInferenceExtensionTests.cs (6)
107var client = useKeyed ? 108host.Services.GetKeyedService<IChatClient>("inference") : 109host.Services.GetService<IChatClient>(); 132var client = useKeyed ? 133host.Services.GetKeyedService<IChatClient>("inference") : 134host.Services.GetService<IChatClient>();
Aspire.Azure.AI.OpenAI.Tests (23)
AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs (20)
35var client = useKeyed ? 36host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 37host.Services.GetRequiredService<IChatClient>(); 65var client = useKeyed ? 66host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 67host.Services.GetRequiredService<IChatClient>(); 93var client = useKeyed ? 94host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 95host.Services.GetRequiredService<IChatClient>(); 125host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 126host.Services.GetRequiredService<IChatClient>(); 156host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 157host.Services.GetRequiredService<IChatClient>(); 186var client = useKeyed ? 187host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 188host.Services.GetRequiredService<IChatClient>(); 213var client = useKeyed ? 214host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 215host.Services.GetRequiredService<IChatClient>(); 220static Task<ChatResponse> TestMiddleware(IEnumerable<ChatMessage> list, ChatOptions? options, IChatClient client, CancellationToken token)
AspireConfigurableOpenAIExtensionsTests.cs (3)
243var chatClient = useKeyed ? 244host.Services.GetRequiredKeyedService<IChatClient>("chat") : 245host.Services.GetRequiredService<IChatClient>();
Aspire.OpenAI (8)
AspireOpenAIClientBuilderChatClientExtensions.cs (8)
13/// Provides extension methods for registering <see cref="IChatClient"/> as a singleton in the services provided by the <see cref="IHostApplicationBuilder"/>. 18/// Registers a singleton <see cref="IChatClient"/> in the services provided by the <paramref name="builder"/>. 22/// <returns>A <see cref="ChatClientBuilder"/> that can be used to build a pipeline around the inner <see cref="IChatClient"/>.</returns> 34/// Registers a keyed singleton <see cref="IChatClient"/> in the services provided by the <paramref name="builder"/>. 37/// <param name="serviceKey">The service key with which the <see cref="IChatClient"/> will be registered.</param> 39/// <returns>A <see cref="ChatClientBuilder"/> that can be used to build a pipeline around the inner <see cref="IChatClient"/>.</returns> 58private static IChatClient CreateInnerChatClient( 68var result = openAiClient.GetChatClient(deploymentName).AsIChatClient();
Aspire.OpenAI.Tests (23)
AspireOpenAIClientBuilderChatClientExtensionsTests.cs (23)
38var client = useKeyed ? 39host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 40host.Services.GetRequiredService<IChatClient>(); 68var client = useKeyed ? 69host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 70host.Services.GetRequiredService<IChatClient>(); 96var client = useKeyed ? 97host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 98host.Services.GetRequiredService<IChatClient>(); 128host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 129host.Services.GetRequiredService<IChatClient>(); 159host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 160host.Services.GetRequiredService<IChatClient>(); 189var client = useKeyed ? 190host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 191host.Services.GetRequiredService<IChatClient>(); 216var client = useKeyed ? 217host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 218host.Services.GetRequiredService<IChatClient>(); 249var client = useKeyed ? 250host.Services.GetRequiredKeyedService<IChatClient>("openai_chatclient") : 251host.Services.GetRequiredService<IChatClient>(); 268private static Task<ChatResponse> TestMiddleware(IEnumerable<ChatMessage> list, ChatOptions? options, IChatClient client, CancellationToken token)
Microsoft.Extensions.AI (98)
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\CachingChatClient.cs (6)
28/// <param name="innerClient">The underlying <see cref="IChatClient"/>.</param> 29protected CachingChatClient(IChatClient innerClient) 157/// This is used when there is a call to <see cref="IChatClient.GetResponseAsync"/>. 167/// This is used when there is a call to <see cref="IChatClient.GetStreamingResponseAsync"/>. 177/// This is used when there is a call to <see cref="IChatClient.GetResponseAsync"/>. 189/// This is used when there is a call to <see cref="IChatClient.GetStreamingResponseAsync"/>.
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\ChatClientBuilderChatClientExtensions.cs (2)
9/// <summary>Provides extension methods for working with <see cref="IChatClient"/> in the context of <see cref="ChatClientBuilder"/>.</summary> 20public static ChatClientBuilder AsBuilder(this IChatClient innerClient)
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));
ChatCompletion\ChatClientStructuredOutputExtensions.cs (13)
21/// Provides extension methods on <see cref="IChatClient"/> that simplify working with structured output. 38/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 49this IChatClient chatClient, 57/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 69this IChatClient chatClient, 77/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 88this IChatClient chatClient, 96/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 108this IChatClient chatClient, 117/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 129this IChatClient chatClient, 138/// <param name="chatClient">The <see cref="IChatClient"/>.</param> 151this IChatClient chatClient,
ChatCompletion\ConfigureOptionsChatClient.cs (1)
30public ConfigureOptionsChatClient(IChatClient innerClient, Action<ChatOptions> configure)
ChatCompletion\DistributedCachingChatClient.cs (3)
31/// The provided implementation of <see cref="IChatClient"/> is thread-safe for concurrent use so long as the employed 44/// <param name="innerClient">The underlying <see cref="IChatClient"/>.</param> 46public DistributedCachingChatClient(IChatClient innerClient, IDistributedCache storage)
ChatCompletion\DistributedCachingChatClientBuilderExtensions.cs (1)
13/// Extension methods for adding a <see cref="DistributedCachingChatClient"/> to an <see cref="IChatClient"/> pipeline.
ChatCompletion\FunctionInvocationContext.cs (3)
96/// If multiple function call requests are issued as part of a single iteration (a single response from the inner <see cref="IChatClient"/>), 104/// <see cref="IChatClient.GetStreamingResponseAsync"/> call as opposed to a <see cref="IChatClient.GetResponseAsync"/> call.
ChatCompletion\FunctionInvokingChatClient.cs (9)
37/// The provided implementation of <see cref="IChatClient"/> is thread-safe for concurrent use so long as the 72/// <param name="innerClient">The underlying <see cref="IChatClient"/>, or the next instance in a chain of clients.</param> 75public FunctionInvokingChatClient(IChatClient innerClient, ILoggerFactory? loggerFactory = null, IServiceProvider? functionInvocationServices = null) 97/// in the chat history when calling the underlying <see cref="IChatClient"/>. 101/// when calling the underlying <see cref="IChatClient"/>. 113/// Setting the value to <see langword="true"/> can help the underlying <see cref="IChatClient"/> bypass problems on 185/// controlled by <see cref="IncludeDetailedErrors"/>). This allows the <see cref="IChatClient"/> to 239Throw.InvalidOperationException($"The inner {nameof(IChatClient)} returned a null {nameof(ChatResponse)}."); 335Throw.InvalidOperationException($"The inner {nameof(IChatClient)} streamed a null {nameof(ChatResponseUpdate)}.");
ChatCompletion\LoggingChatClient.cs (3)
18/// The provided implementation of <see cref="IChatClient"/> is thread-safe for concurrent use so long as the 37/// <param name="innerClient">The underlying <see cref="IChatClient"/>.</param> 39public LoggingChatClient(IChatClient innerClient, ILogger logger)
ChatCompletion\OpenTelemetryChatClient.cs (2)
50/// <param name="innerClient">The underlying <see cref="IChatClient"/>.</param> 53public OpenTelemetryChatClient(IChatClient innerClient, ILogger? logger = null, string? sourceName = null)
Microsoft.Extensions.AI.Abstractions (51)
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 (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,
ChatCompletion\ChatClientMetadata.cs (2)
8/// <summary>Provides metadata about an <see cref="IChatClient"/>.</summary> 37/// This value can be <see langword="null"/> if no default model is set on the corresponding <see cref="IChatClient"/>.
ChatCompletion\ChatMessage.cs (1)
12/// <summary>Represents a chat message used by an <see cref="IChatClient" />.</summary>
ChatCompletion\ChatOptions.cs (7)
91/// If <see langword="false"/>, the <see cref="IChatClient"/> is asked to return a maximum of one tool call per request. 119/// The underlying <see cref="IChatClient" /> implementation may have its own representation of options. 120/// When <see cref="IChatClient.GetResponseAsync" /> or <see cref="IChatClient.GetStreamingResponseAsync" /> 123/// which concrete <see cref="IChatClient" /> is being used and how it represents options, a new instance of that 124/// implementation-specific options type may be returned by this callback, for the <see cref="IChatClient" /> 133public Func<IChatClient, object?>? RawRepresentationFactory { get; set; }
ChatCompletion\ChatResponse.cs (4)
17/// request to a <see cref="IChatClient"/> may actually generate multiple roundtrips to an inner <see cref="IChatClient"/> 68/// Some <see cref="IChatClient"/> implementations are capable of storing the state for a conversation, such that 69/// the input messages supplied to <see cref="IChatClient.GetResponseAsync"/> need only be the additional messages beyond
ChatCompletion\ChatResponseUpdate.cs (3)
13/// Represents a single streaming response chunk from an <see cref="IChatClient"/>. 121/// Some <see cref="IChatClient"/> implementations are capable of storing the state for a conversation, such that 122/// the input messages supplied to <see cref="IChatClient.GetStreamingResponseAsync"/> need only be the additional messages beyond
ChatCompletion\ChatToolMode.cs (4)
9/// Describes how tools should be selected by a <see cref="IChatClient"/>. 34/// instances, and the <see cref="IChatClient"/> is free to invoke zero or more of them. 43/// instances, but the <see cref="IChatClient"/> should not request the invocation of 44/// any of them. This can be used when the <see cref="IChatClient"/> should know about
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 around an underlying <see cref="IChatClient"/>. 26protected DelegatingChatClient(IChatClient innerClient) 38/// <summary>Gets the inner <see cref="IChatClient" />.</summary> 39protected IChatClient InnerClient { get; }
ChatCompletion\IChatClient.cs (7)
15/// sent to the underlying provider or returned from it. Unless a specific <see cref="IChatClient"/> implementation 19/// Unless otherwise specified, all members of <see cref="IChatClient"/> are thread-safe for concurrent use. 20/// It is expected that all implementations of <see cref="IChatClient"/> support being used by multiple requests concurrently. 24/// However, implementations of <see cref="IChatClient"/> might mutate the arguments supplied to <see cref="GetResponseAsync"/> and 27/// that no <see cref="IChatClient"/> instances are used which might employ such mutation. For example, the ConfigureOptions method is 59/// <summary>Asks the <see cref="IChatClient"/> for an object of the specified type <paramref name="serviceType"/>.</summary> 65/// The purpose of this method is to allow for the retrieval of strongly-typed services that might be provided by the <see cref="IChatClient"/>,
ChatCompletion\NoneChatToolMode.cs (1)
9/// Indicates that an <see cref="IChatClient"/> should not request the invocation of any tools.
Utilities\AIJsonSchemaTransformCache.cs (2)
17/// to their corresponding JSON schemas transformed according to the specified <see cref="TransformOptions"/> policy. It is intended for use by <see cref="IChatClient"/> 21/// It is recommended <see cref="IChatClient"/> implementations with schema transformation requirements should create a single static instance of this cache.
Microsoft.Extensions.AI.Abstractions.Tests (7)
ChatCompletion\ChatClientExtensionsTests.cs (3)
42if (serviceType == typeof(IChatClient)) 57Assert.Null(client.GetService<IChatClient>()); 69Assert.Throws<InvalidOperationException>(() => client.GetRequiredService<IChatClient>());
ChatCompletion\ChatOptionsTests.cs (1)
75Func<IChatClient, object?> rawRepresentationFactory = (c) => null;
ChatCompletion\DelegatingChatClientTests.cs (3)
126var client = delegating.GetService<IChatClient>(expectedKey); 163private sealed class NoOpDelegatingChatClient(IChatClient innerClient)
Microsoft.Extensions.AI.AzureAIInference (5)
AzureAIInferenceChatClient.cs (2)
24/// <summary>Represents an <see cref="IChatClient"/> for an Azure AI Inference <see cref="ChatCompletionsClient"/>.</summary> 72object? IChatClient.GetService(Type serviceType, object? serviceKey)
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 can be used to converse via the <see cref="ChatCompletionsClient"/>.</returns> 15public static IChatClient AsIChatClient(
Microsoft.Extensions.AI.AzureAIInference.Tests (26)
AzureAIInferenceChatClientIntegrationTests.cs (1)
8protected override IChatClient? CreateChatClient() =>
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 (13)
ChatConfiguration.cs (5)
12/// Specifies the <see cref="IChatClient"/> that should be used when evaluation is performed using an AI model. 14/// <param name="chatClient">An <see cref="IChatClient"/> that can be used to communicate with an AI model.</param> 15public sealed class ChatConfiguration(IChatClient chatClient) 18/// Gets an <see cref="IChatClient"/> that can be used to communicate with an AI model. 20public IChatClient ChatClient { get; } = chatClient;
CompositeEvaluator.cs (1)
91/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that should be used if one or
EvaluatorExtensions.cs (6)
33/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that should be used if one or 76/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that should be used if one or 118/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that should be used if one or 158/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that should be used if one or 206/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that should be used if one or 251/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that should be used if one or
IEvaluator.cs (1)
43/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that should be used if one or
Microsoft.Extensions.AI.Evaluation.Integration.Tests (8)
QualityEvaluatorTests.cs (4)
89IChatClient chatClient = scenarioRun.ChatConfiguration!.ChatClient; 129IChatClient chatClient = scenarioRun.ChatConfiguration!.ChatClient; 166IChatClient chatClient = scenarioRun.ChatConfiguration!.ChatClient; 201IChatClient chatClient = scenarioRun.ChatConfiguration!.ChatClient;
SafetyEvaluatorTests.cs (3)
132IChatClient chatClient = scenarioRun.ChatConfiguration!.ChatClient; 194IChatClient chatClient = scenarioRun.ChatConfiguration!.ChatClient; 522IChatClient chatClient = scenarioRun.ChatConfiguration!.ChatClient;
Setup.cs (1)
26IChatClient chatClient = azureClient.GetChatClient(Settings.Current.DeploymentName).AsIChatClient();
Microsoft.Extensions.AI.Evaluation.Reporting (10)
ReportingConfiguration.cs (6)
36/// Gets a <see cref="Evaluation.ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that is used by 54/// the configured <see cref="IChatClient"/> and the <see cref="ChatOptions"/> that are supplied as part of 108/// A <see cref="Evaluation.ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that is used by 214IChatClient originalChatClient = chatConfiguration.ChatClient; 230IChatClient chatClient; 267private static IEnumerable<string> GetCachingKeysForChatClient(IChatClient chatClient)
ResponseCachingChatClient.cs (1)
21IChatClient originalChatClient,
ScenarioRun.cs (1)
89/// Gets a <see cref="Evaluation.ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that is used by
SimpleChatClient.cs (1)
16internal SimpleChatClient(IChatClient originalChatClient, ChatDetails chatDetails)
Storage\DiskBasedReportingConfiguration.cs (1)
28/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that is used by AI-based
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (1)
Storage\AzureStorageReportingConfiguration.cs (1)
28/// A <see cref="ChatConfiguration"/> that specifies the <see cref="IChatClient"/> that is used by AI-based
Microsoft.Extensions.AI.Evaluation.Safety (9)
ContentSafetyChatClient.cs (3)
26private readonly IChatClient? _originalChatClient; 31IChatClient? originalChatClient = null) 180Failed to invoke '{nameof(IChatClient)}.{callerMemberName}()'.
ContentSafetyEvaluator.cs (2)
65/// The <see cref="IChatClient"/> that should be used to communicate with the Azure AI Foundry Evaluation Service 89IChatClient contentSafetyServiceChatClient,
ContentSafetyServiceConfigurationExtensions.cs (3)
26/// a new <see cref="IChatClient"/> that can be used both to communicate with the AI model that 62/// The original <see cref="IChatClient"/>. The returned <see cref="ChatConfiguration.ChatClient"/> will be a 73IChatClient originalChatClient)
ProtectedMaterialEvaluator.cs (1)
76IChatClient chatClient = chatConfiguration.ChatClient;
Microsoft.Extensions.AI.Integration.Tests (16)
CallCountingChatClient.cs (1)
13internal sealed class CallCountingChatClient(IChatClient innerClient) : DelegatingChatClient(innerClient)
ChatClientIntegrationTests.cs (11)
30private readonly IChatClient? _chatClient; 43protected abstract IChatClient? CreateChatClient(); 563using var chatClient = CreateChatClient()! 602using var chatClient = CreateChatClient()! 644using var chatClient = CreateChatClient()! 677using var chatClient = CreateChatClient()!.AsBuilder() 696using var chatClient = CreateChatClient()!.AsBuilder() 718using var chatClient = CreateChatClient()! 744using var chatClient = CreateChatClient()! 776var chatClient = CreateChatClient()!.AsBuilder() 927var captureOutputChatClient = _chatClient.AsBuilder()
PromptBasedFunctionCallingChatClient.cs (1)
31internal sealed class PromptBasedFunctionCallingChatClient(IChatClient innerClient)
ReducingChatClientTests.cs (3)
20/// <summary>Provides an example of a custom <see cref="IChatClient"/> for reducing chat message lists.</summary> 40using var client = innerClient 68public ReducingChatClient(IChatClient innerClient, IChatReducer reducer)
Microsoft.Extensions.AI.Ollama (2)
OllamaChatClient.cs (2)
23/// <summary>Represents an <see cref="IChatClient"/> for Ollama.</summary> 208object? IChatClient.GetService(Type serviceType, object? serviceKey)
Microsoft.Extensions.AI.Ollama.Tests (12)
OllamaChatClientIntegrationTests.cs (4)
16protected override IChatClient? CreateChatClient() => 34using var chatClient = CreateChatClient()! 58using var chatClient = CreateChatClient()! 106private sealed class AssertNoToolsDefinedChatClient(IChatClient innerClient) : DelegatingChatClient(innerClient)
OllamaChatClientTests.cs (8)
49Assert.Same(client, client.GetService<IChatClient>()); 51using IChatClient pipeline = client 64Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>()); 73using IChatClient chatClient = new OllamaChatClient(endpoint, model); 172using IChatClient client = new OllamaChatClient("http://localhost:11434", "llama3.1", httpClient); 265using IChatClient client = new OllamaChatClient("http://localhost:11434", httpClient: httpClient); 369using IChatClient client = new OllamaChatClient("http://localhost:11434", "llama3.1", httpClient) 460using IChatClient client = new OllamaChatClient("http://localhost:11434", "llama3.1", httpClient)
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (1)
OllamaSharpChatClientIntegrationTests.cs (1)
11protected override IChatClient? CreateChatClient() =>
Microsoft.Extensions.AI.OpenAI (10)
OpenAIChatClient.cs (2)
25/// <summary>Represents an <see cref="IChatClient"/> for an OpenAI <see cref="OpenAIClient"/> or <see cref="ChatClient"/>.</summary> 68object? IChatClient.GetService(Type serviceType, object? serviceKey)
OpenAIClientExtensions.cs (6)
16/// <summary>Gets an <see cref="IChatClient"/> for use with this <see cref="ChatClient"/>.</summary> 18/// <returns>An <see cref="IChatClient"/> that can be used to converse via the <see cref="ChatClient"/>.</returns> 19public static IChatClient AsIChatClient(this ChatClient chatClient) => 22/// <summary>Gets an <see cref="IChatClient"/> for use with this <see cref="OpenAIResponseClient"/>.</summary> 24/// <returns>An <see cref="IChatClient"/> that can be used to converse via the <see cref="OpenAIResponseClient"/>.</returns> 25public static IChatClient AsIChatClient(this OpenAIResponseClient responseClient) =>
OpenAIResponseChatClient.cs (2)
25/// <summary>Represents an <see cref="IChatClient"/> for an <see cref="OpenAIResponseClient"/>.</summary> 62object? IChatClient.GetService(Type serviceType, object? serviceKey)
Microsoft.Extensions.AI.OpenAI.Tests (36)
OpenAIChatClientIntegrationTests.cs (1)
8protected override IChatClient? CreateChatClient() =>
OpenAIChatClientTests.cs (25)
45IChatClient chatClient = client.GetChatClient(model).AsIChatClient(); 62IChatClient chatClient = openAIClient.AsIChatClient(); 64Assert.Same(chatClient, chatClient.GetService<IChatClient>()); 70using IChatClient pipeline = chatClient 83Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>()); 90IChatClient chatClient = openAIClient.AsIChatClient(); 92Assert.Same(chatClient, chatClient.GetService<IChatClient>()); 95using IChatClient pipeline = chatClient 108Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>()); 158using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 236using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 319using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini"); 398using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini"); 483using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini"); 559using IChatClient client = CreateChatClient(httpClient, modelId: "gpt-4o-mini"); 669using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 759using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 866using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 962using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 1081using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 1165using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 1264using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 1404using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 1524using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini"); 1566private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
OpenAIResponseClientIntegrationTests.cs (1)
8protected override IChatClient? CreateChatClient() =>
OpenAIResponseClientTests.cs (9)
44IChatClient chatClient = client.GetOpenAIResponseClient(model).AsIChatClient(); 55IChatClient chatClient = openAIClient.AsIChatClient(); 57Assert.Same(chatClient, chatClient.GetService<IChatClient>()); 60using IChatClient pipeline = chatClient 73Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>()); 152using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini"); 252using IChatClient client = CreateResponseClient(httpClient, "gpt-4o-mini"); 368using IChatClient client = CreateResponseClient(httpClient, modelId: "gpt-4o-mini"); 415private static IChatClient CreateResponseClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Tests (56)
ChatCompletion\ChatClientBuilderTest.cs (5)
61Assert.Throws<ArgumentNullException>("innerClient", () => new ChatClientBuilder((IChatClient)null!)); 62Assert.Throws<ArgumentNullException>("innerClient", () => ((IChatClient)null!).AsBuilder()); 68Assert.Throws<ArgumentNullException>("innerClientFactory", () => new ChatClientBuilder((Func<IServiceProvider, IChatClient>)null!)); 99private sealed class InnerClientCapturingChatClient(string name, IChatClient innerClient) : DelegatingChatClient(innerClient) 104public new IChatClient InnerClient => base.InnerClient;
ChatCompletion\ConfigureOptionsChatClientTests.cs (2)
41using IChatClient innerClient = new TestChatClient 58using var client = innerClient
ChatCompletion\DependencyInjectionPatterns.cs (30)
26var instance1 = scope1.ServiceProvider.GetRequiredService<IChatClient>(); 27var instance1Copy = scope1.ServiceProvider.GetRequiredService<IChatClient>(); 28var instance2 = scope2.ServiceProvider.GetRequiredService<IChatClient>(); 50var instance1 = scope1.ServiceProvider.GetRequiredService<IChatClient>(); 51var instance1Copy = scope1.ServiceProvider.GetRequiredService<IChatClient>(); 52var instance2 = scope2.ServiceProvider.GetRequiredService<IChatClient>(); 73Assert.Null(services.GetService<IChatClient>()); 75var instance1 = scope1.ServiceProvider.GetRequiredKeyedService<IChatClient>("mykey"); 76var instance1Copy = scope1.ServiceProvider.GetRequiredKeyedService<IChatClient>("mykey"); 77var instance2 = scope2.ServiceProvider.GetRequiredKeyedService<IChatClient>("mykey"); 99Assert.Null(services.GetService<IChatClient>()); 101var instance1 = scope1.ServiceProvider.GetRequiredKeyedService<IChatClient>("mykey"); 102var instance1Copy = scope1.ServiceProvider.GetRequiredKeyedService<IChatClient>("mykey"); 103var instance2 = scope2.ServiceProvider.GetRequiredKeyedService<IChatClient>("mykey"); 126Assert.Equal(typeof(IChatClient), sd.ServiceType); 148Assert.Equal(typeof(IChatClient), sd.ServiceType); 248public class SingletonMiddleware(IChatClient inner, IServiceProvider services) : DelegatingChatClient(inner) 250public new IChatClient InnerClient => base.InnerClient;
ChatCompletion\DistributedCachingChatClientTest.cs (1)
807private sealed class CachingChatClientWithCustomKey(IChatClient innerClient, IDistributedCache storage)
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
841using IChatClient service = innerClient.AsBuilder().UseFunctionInvocation().Build(); 965IChatClient service = configurePipeline(innerClient.AsBuilder()).Build(services); 1059IChatClient service = configurePipeline(innerClient.AsBuilder()).Build(services);
ChatCompletion\LoggingChatClientTests.cs (5)
30Assert.Same(innerClient, innerClient.AsBuilder().UseLogging(NullLoggerFactory.Instance).Build().GetService(typeof(IChatClient))); 55using IChatClient innerClient = new TestChatClient 63using IChatClient client = innerClient 100using IChatClient innerClient = new TestChatClient 112using IChatClient client = innerClient
ChatCompletion\UseDelegateChatClientTests.cs (10)
34using IChatClient innerClient = new TestChatClient 55using IChatClient client = new ChatClientBuilder(innerClient) 83using IChatClient innerClient = new TestChatClient 95using IChatClient client = new ChatClientBuilder(innerClient) 125using IChatClient innerClient = new TestChatClient 137using IChatClient client = new ChatClientBuilder(innerClient) 147IEnumerable<ChatMessage> messages, ChatOptions? options, IChatClient innerClient, [EnumeratorCancellation] CancellationToken cancellationToken) 176using IChatClient innerClient = new TestChatClient 197using IChatClient client = new ChatClientBuilder(innerClient) 218IEnumerable<ChatMessage> messages, ChatOptions? options, IChatClient innerClient, [EnumeratorCancellation] CancellationToken cancellationToken)