8 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 (1)
Microsoft.Extensions.AI.Tests (1)
Microsoft.ML.GenAI.Core (1)
278 references to IChatClient
Aspire.Azure.AI.OpenAI.Tests (20)
Aspire.OpenAI (8)
Aspire.OpenAI.Tests (20)
Microsoft.Extensions.AI (93)
ChatCompletion\AnonymousDelegatingChatClient.cs (10)
20private readonly Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? _completeFunc;
28private readonly Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? _completeStreamingFunc;
48public AnonymousDelegatingChatClient(IChatClient innerClient, CompleteSharedFunc sharedFunc)
73IChatClient innerClient,
74Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? completeFunc,
75Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? completeStreamingFunc)
196/// Represents a method used to call <see cref="IChatClient.CompleteAsync"/> or <see cref="IChatClient.CompleteStreamingAsync"/>.
201/// A delegate that provides the implementation for the inner client's <see cref="IChatClient.CompleteAsync"/> or
202/// <see cref="IChatClient.CompleteStreamingAsync"/>. It should be invoked to continue the pipeline. It accepts
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>
22public ChatClientBuilder(IChatClient innerClient)
29/// <param name="innerClientFactory">A callback that produces the inner <see cref="IChatClient"/> that represents the underlying backend.</param>
30public ChatClientBuilder(Func<IServiceProvider, IChatClient> innerClientFactory)
35/// <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>
37/// The <see cref="IServiceProvider"/> that should provide services to the <see cref="IChatClient"/> instances.
40/// <returns>An instance of <see cref="IChatClient"/> that represents the entire pipeline.</returns>
41public IChatClient Build(IServiceProvider? services = null)
44var chatClient = _innerClientFactory(services);
54$"Ensure that the callbacks passed to {nameof(Use)} return non-null {nameof(IChatClient)} instances.");
64public ChatClientBuilder Use(Func<IChatClient, IChatClient> clientFactory)
74public ChatClientBuilder Use(Func<IChatClient, IServiceProvider, IChatClient> clientFactory)
84/// an implementation for both <see cref="IChatClient.CompleteAsync"/> and <see cref="IChatClient.CompleteStreamingAsync"/>.
87/// A delegate that provides the implementation for both <see cref="IChatClient.CompleteAsync"/> and
88/// <see cref="IChatClient.CompleteStreamingAsync"/>. In addition to the arguments for the operation, it's
107/// an implementation for both <see cref="IChatClient.CompleteAsync"/> and <see cref="IChatClient.CompleteStreamingAsync"/>.
110/// A delegate that provides the implementation for <see cref="IChatClient.CompleteAsync"/>. When <see langword="null"/>,
111/// <paramref name="completeStreamingFunc"/> must be non-null, and the implementation of <see cref="IChatClient.CompleteAsync"/>
115/// A delegate that provides the implementation for <see cref="IChatClient.CompleteStreamingAsync"/>. When <see langword="null"/>,
116/// <paramref name="completeFunc"/> must be non-null, and the implementation of <see cref="IChatClient.CompleteStreamingAsync"/>
122/// <paramref name="completeFunc"/> will provide the implementation of <see cref="IChatClient.CompleteAsync"/>, and
123/// <paramref name="completeStreamingFunc"/> will provide the implementation of <see cref="IChatClient.CompleteStreamingAsync"/>.
125/// is supplied without <paramref name="completeStreamingFunc"/>, the implementation of <see cref="IChatClient.CompleteStreamingAsync"/>
128/// <see cref="IChatClient.CompleteAsync"/> will be implemented by combining the updates from <paramref name="completeStreamingFunc"/>.
132Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? completeFunc,
133Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, IAsyncEnumerable<StreamingChatCompletionUpdate>>? completeStreamingFunc)
Microsoft.Extensions.AI.Abstractions (24)
Microsoft.Extensions.AI.Abstractions.Tests (3)
Microsoft.Extensions.AI.AzureAIInference (4)
Microsoft.Extensions.AI.AzureAIInference.Tests (13)
Microsoft.Extensions.AI.Integration.Tests (5)
Microsoft.Extensions.AI.Ollama (1)
Microsoft.Extensions.AI.Ollama.Tests (12)
Microsoft.Extensions.AI.OpenAI (7)
Microsoft.Extensions.AI.OpenAI.Tests (19)
OpenAIChatClientTests.cs (18)
74IChatClient chatClient = client.AsChatClient(model);
89IChatClient chatClient = openAIClient.AsChatClient("model");
91Assert.Same(chatClient, chatClient.GetService<IChatClient>());
98using IChatClient pipeline = chatClient
111Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
118IChatClient chatClient = openAIClient.AsChatClient();
120Assert.Same(chatClient, chatClient.GetService<IChatClient>());
123using IChatClient pipeline = chatClient
136Assert.IsType<FunctionInvokingChatClient>(pipeline.GetService<IChatClient>());
181using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
246using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
351using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
452using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
543using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
656using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
750using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
883using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
925private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Tests (49)