1 type derived from ChatCompletion
Microsoft.Extensions.AI (1)
ChatCompletion\ChatCompletion{T}.cs (1)
22public class ChatCompletion<T> : ChatCompletion
14 instantiations of ChatCompletion
Aspire.Azure.AI.OpenAI.Tests (1)
AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs (1)
221=> Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "Hello from middleware")));
Aspire.OpenAI.Tests (1)
AspireOpenAIClientBuilderChatClientExtensionsTests.cs (1)
222=> Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "Hello from middleware")));
Microsoft.Extensions.AI.Abstractions.Tests (5)
ChatCompletion\ChatCompletionTests.cs (5)
16Assert.Throws<ArgumentNullException>("message", () => new ChatCompletion((ChatMessage)null!)); 17Assert.Throws<ArgumentNullException>("choices", () => new ChatCompletion((IList<ChatMessage>)null!)); 25ChatCompletion completion = new(message); 40ChatCompletion completion = new(messages); 208ChatCompletion completion = new(new ChatMessage(new ChatRole("customRole"), "Text"))
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
133return new ChatCompletion(returnMessages)
Microsoft.Extensions.AI.Tests (6)
ChatCompletion\ConfigureOptionsChatClientTests.cs (1)
37ChatCompletion expectedCompletion = new(Array.Empty<ChatMessage>());
ChatCompletion\FunctionInvokingChatClientTests.cs (2)
520return new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])); 587return YieldAsync(new ChatCompletion(new ChatMessage(ChatRole.Assistant, [.. plan[contents.Count].Contents])).ToStreamingChatCompletionUpdates());
ChatCompletion\UseDelegateChatClientTests.cs (3)
50return Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "hello"))); 99return Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "hello"))); 192return Task.FromResult(new ChatCompletion(new ChatMessage(ChatRole.Assistant, "non-streaming hello")));
120 references to ChatCompletion
Aspire.Azure.AI.OpenAI.Tests (2)
AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs (2)
217var completion = await client.CompleteAsync("Whatever"); 220static Task<ChatCompletion> TestMiddleware(IList<ChatMessage> list, ChatOptions? options, IChatClient client, CancellationToken token)
Aspire.OpenAI.Tests (2)
AspireOpenAIClientBuilderChatClientExtensionsTests.cs (2)
218var completion = await client.CompleteAsync("Whatever"); 221static Task<ChatCompletion> TestMiddleware(IList<ChatMessage> list, ChatOptions? options, IChatClient client, CancellationToken token)
Microsoft.Extensions.AI (34)
ChatCompletion\AnonymousDelegatingChatClient.cs (7)
20private readonly Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? _completeFunc; 74Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? completeFunc, 85public override Task<ChatCompletion> CompleteAsync( 94async Task<ChatCompletion> CompleteViaSharedAsync(IList<ChatMessage> chatMessages, ChatOptions? options, CancellationToken cancellationToken) 96ChatCompletion? completion = null; 169static async IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsyncViaCompleteAsync(Task<ChatCompletion> task) 171ChatCompletion completion = await task.ConfigureAwait(false);
ChatCompletion\CachingChatClient.cs (7)
48public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 134/// Returns a previously cached <see cref="ChatCompletion"/>, if available. 140protected abstract Task<ChatCompletion?> ReadCacheAsync(string key, CancellationToken cancellationToken); 152/// Stores a <see cref="ChatCompletion"/> in the underlying cache. 156/// <param name="value">The <see cref="ChatCompletion"/> to be stored.</param> 159protected abstract Task WriteCacheAsync(string key, ChatCompletion value, CancellationToken cancellationToken); 166/// <param name="value">The <see cref="ChatCompletion"/> to be stored.</param>
ChatCompletion\ChatClientBuilder.cs (1)
132Func<IList<ChatMessage>, ChatOptions?, IChatClient, CancellationToken, Task<ChatCompletion>>? completeFunc,
ChatCompletion\ChatClientStructuredOutputExtensions.cs (1)
187var result = await chatClient.CompleteAsync(chatMessages, options, cancellationToken).ConfigureAwait(false);
ChatCompletion\ChatCompletion{T}.cs (3)
20/// You can access the underlying JSON response on the <see cref="ChatCompletion.Message"/> property. 31/// <param name="completion">The unstructured <see cref="ChatCompletion"/> that is being wrapped.</param> 33public ChatCompletion(ChatCompletion completion, JsonSerializerOptions serializerOptions)
ChatCompletion\ConfigureOptionsChatClient.cs (1)
37public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
ChatCompletion\DistributedCachingChatClient.cs (5)
46protected override async Task<ChatCompletion?> ReadCacheAsync(string key, CancellationToken cancellationToken) 53return (ChatCompletion?)JsonSerializer.Deserialize(existingJson, _jsonSerializerOptions.GetTypeInfo(typeof(ChatCompletion))); 74protected override async Task WriteCacheAsync(string key, ChatCompletion value, CancellationToken cancellationToken) 80var newJson = JsonSerializer.SerializeToUtf8Bytes(value, _jsonSerializerOptions.GetTypeInfo(typeof(ChatCompletion)));
ChatCompletion\FunctionInvokingChatClient.cs (2)
190public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 193ChatCompletion? response;
ChatCompletion\LoggingChatClient.cs (2)
46public override async Task<ChatCompletion> CompleteAsync( 63var completion = await base.CompleteAsync(chatMessages, options, cancellationToken).ConfigureAwait(false);
ChatCompletion\OpenTelemetryChatClient.cs (5)
122public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) 133ChatCompletion? completion = null; 303ChatCompletion? completion, 381void AddMetricTags(ref TagList tags, string? requestModelId, ChatCompletion? completions) 445private void LogChatCompletion(ChatCompletion completion)
Microsoft.Extensions.AI.Abstractions (28)
ChatCompletion\ChatClientExtensions.cs (1)
36public static Task<ChatCompletion> CompleteAsync(
ChatCompletion\ChatCompletion.cs (6)
18/// <summary>Initializes a new instance of the <see cref="ChatCompletion"/> class.</summary> 26/// <summary>Initializes a new instance of the <see cref="ChatCompletion"/> class.</summary> 54throw new InvalidOperationException($"The {nameof(ChatCompletion)} instance does not contain any {nameof(ChatMessage)} choices."); 78/// If a <see cref="ChatCompletion"/> is created to represent some underlying object from another object 110/// <summary>Creates an array of <see cref="StreamingChatCompletionUpdate" /> instances that represent this <see cref="ChatCompletion" />.</summary> 111/// <returns>An array of <see cref="StreamingChatCompletionUpdate" /> instances that may be used to represent this <see cref="ChatCompletion" />.</returns>
ChatCompletion\DelegatingChatClient.cs (1)
54public virtual Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
ChatCompletion\IChatClient.cs (1)
37Task<ChatCompletion> CompleteAsync(
ChatCompletion\StreamingChatCompletionUpdate.cs (4)
16/// Conceptually, this combines the roles of <see cref="ChatCompletion"/> and <see cref="ChatMessage"/> 32/// The relationship between <see cref="ChatCompletion"/> and <see cref="StreamingChatCompletionUpdate"/> is 34/// <see cref="ChatCompletion.ToStreamingChatCompletionUpdates"/>, which enable bidirectional conversions 37/// only one slot for such an object available in <see cref="ChatCompletion.RawRepresentation"/>.
ChatCompletion\StreamingChatCompletionUpdateExtensions.cs (14)
24/// <summary>Combines <see cref="StreamingChatCompletionUpdate"/> instances into a single <see cref="ChatCompletion"/>.</summary> 32/// <returns>The combined <see cref="ChatCompletion"/>.</returns> 33public static ChatCompletion ToChatCompletion( 38ChatCompletion completion = new([]); 51/// <summary>Combines <see cref="StreamingChatCompletionUpdate"/> instances into a single <see cref="ChatCompletion"/>.</summary> 60/// <returns>The combined <see cref="ChatCompletion"/>.</returns> 61public static Task<ChatCompletion> ToChatCompletionAsync( 68static async Task<ChatCompletion> ToChatCompletionAsync( 71ChatCompletion completion = new([]); 88/// <param name="completion">The <see cref="ChatCompletion"/> object whose properties should be updated based on <paramref name="update"/>.</param> 89private static void ProcessUpdate(StreamingChatCompletionUpdate update, Dictionary<int, ChatMessage> messages, ChatCompletion completion) 133/// <param name="completion">The result <see cref="ChatCompletion"/> being built.</param> 135private static void AddMessagesToCompletion(Dictionary<int, ChatMessage> messages, ChatCompletion completion, bool coalesceContent) 152static void AddMessage(ChatCompletion completion, bool coalesceContent, KeyValuePair<int, ChatMessage> entry)
Utilities\AIJsonUtilities.Defaults.cs (1)
58[JsonSerializable(typeof(ChatCompletion))]
Microsoft.Extensions.AI.Abstractions.Tests (21)
ChatCompletion\ChatClientExtensionsTests.cs (1)
71ChatCompletion response = await client.CompleteAsync("hello", expectedOptions, cts.Token);
ChatCompletion\ChatCompletionTests.cs (13)
25ChatCompletion completion = new(message); 40ChatCompletion completion = new(messages); 48ChatCompletion completion = new([]); 58ChatCompletion completion = new([message]); 68ChatCompletion completion = new([ 80ChatCompletion completion = new([]); 87ChatCompletion completion = new([]); 128ChatCompletion original = new( 147ChatCompletion? result = JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.ChatCompletion); 174ChatCompletion completion = new( 185ChatCompletion completion = new( 208ChatCompletion completion = new(new ChatMessage(new ChatRole("customRole"), "Text")) 237ChatCompletion completion = new(
ChatCompletion\DelegatingChatClientTests.cs (1)
36var expectedResult = new TaskCompletionSource<ChatCompletion>();
ChatCompletion\StreamingChatCompletionUpdateExtensionsTests.cs (3)
54ChatCompletion completion = (coalesceContent is bool, useAsync) switch 178ChatCompletion completion = useAsync ? await YieldAsync(updates).ToChatCompletionAsync() : updates.ToChatCompletion(); 202ChatCompletion completion = await YieldAsync(updates).ToChatCompletionAsync();
TestChatClient.cs (2)
17public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; } 23public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
17[JsonSerializable(typeof(ChatCompletion))]
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
80public async Task<ChatCompletion> CompleteAsync(
Microsoft.Extensions.AI.AzureAIInference.Tests (2)
AzureAIInferenceChatClientTests.cs (2)
140var response = await client.CompleteAsync("hello", new() 406var response = await client.CompleteAsync(messages);
Microsoft.Extensions.AI.Integration.Tests (6)
CallCountingChatClient.cs (1)
19public override Task<ChatCompletion> CompleteAsync(
ChatClientIntegrationTests.cs (2)
50var response = await _chatClient.CompleteAsync("What's the biggest animal?"); 103var response = await _chatClient.CompleteAsync("Explain in 10 words how AI works");
PromptBasedFunctionCallingChatClient.cs (1)
40public override async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
17public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; } 23public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
79public async Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.Extensions.AI.Ollama.Tests (2)
OllamaChatClientIntegrationTests.cs (1)
98public override Task<ChatCompletion> CompleteAsync(
OllamaChatClientTests.cs (1)
113var response = await client.CompleteAsync("hello", new()
Microsoft.Extensions.AI.OpenAI (1)
OpenAIChatClient.cs (1)
108public async Task<ChatCompletion> CompleteAsync(
Microsoft.Extensions.AI.OpenAI.Tests (4)
OpenAIChatClientTests.cs (4)
183var response = await client.CompleteAsync("hello", new() 460var response = await client.CompleteAsync(messages); 553var response = await client.CompleteAsync(messages); 904var response = await client.CompleteAsync(messages);
Microsoft.Extensions.AI.Tests (13)
ChatCompletion\ConfigureOptionsChatClientTests.cs (2)
37ChatCompletion expectedCompletion = new(Array.Empty<ChatMessage>()); 76var completion = await client.CompleteAsync(Array.Empty<ChatMessage>(), providedOptions, cts.Token);
ChatCompletion\FunctionInvokingChatClientTests.cs (2)
526var result = await service.CompleteAsync(chat, options, cts.Token); 593var result = await service.CompleteStreamingAsync(chat, options, cts.Token).ToChatCompletionAsync();
ChatCompletion\UseDelegateChatClientTests.cs (6)
75ChatCompletion completion = await client.CompleteAsync(expectedMessages, expectedOptions, expectedCts.Token); 110var cc = await innerClient.CompleteAsync(chatMessages, options, cancellationToken); 118ChatCompletion completion = await client.CompleteAsync(expectedMessages, expectedOptions, expectedCts.Token); 169ChatCompletion completion = await client.CompleteAsync(expectedMessages, expectedOptions, expectedCts.Token); 213var cc = await innerClient.CompleteAsync(chatMessages, options, cancellationToken); 240ChatCompletion completion = await client.CompleteAsync(expectedMessages, expectedOptions, expectedCts.Token);
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\TestChatClient.cs (2)
17public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatCompletion>>? CompleteAsyncCallback { get; set; } 23public Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
TestJsonSerializerContext.cs (1)
13[JsonSerializable(typeof(ChatCompletion))]
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
37public virtual Task<ChatCompletion> CompleteAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Microsoft.ML.GenAI.LLaMA (1)
Llama3CausalLMChatClient.cs (1)
27public override Task<ChatCompletion> CompleteAsync(
Microsoft.ML.GenAI.Phi (1)
Phi3\Phi3CausalLMChatClient.cs (1)
32public override Task<ChatCompletion> CompleteAsync(