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)
306 references to IChatClient
Aspire.Azure.AI.OpenAI.Tests (20)
Aspire.OpenAI (8)
Aspire.OpenAI.Tests (20)
Microsoft.Extensions.AI (98)
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 (32)
Microsoft.Extensions.AI.Abstractions.Tests (3)
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>());
148using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
215using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
283using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
331using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
367using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
406using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
503using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
585using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
648using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
767using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
854using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
884private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Integration.Tests (5)
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");
870using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1011using IChatClient client = CreateChatClient(httpClient, "gpt-4o-mini");
1061private static IChatClient CreateChatClient(HttpClient httpClient, string modelId) =>
Microsoft.Extensions.AI.Tests (51)