diff --git a/src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseUpdateExtensions.cs b/src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseUpdateExtensions.cs index bfc2c3fd60f..25104461cd9 100644 --- a/src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseUpdateExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseUpdateExtensions.cs @@ -89,10 +89,11 @@ static async Task ToChatResponseAsync( /// The object whose properties should be updated based on . private static void ProcessUpdate(ChatResponseUpdate update, Dictionary messages, ChatResponse response) { - response.ResponseId ??= update.ResponseId; + response.ChatThreadId ??= update.ChatThreadId; response.CreatedAt ??= update.CreatedAt; response.FinishReason ??= update.FinishReason; response.ModelId ??= update.ModelId; + response.ResponseId ??= update.ResponseId; #if NET ChatMessage message = CollectionsMarshal.GetValueRefOrAddDefault(messages, update.ChoiceIndex, out _) ??= diff --git a/src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Azure/Storage/AzureStorageResultStore.cs b/src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Azure/Storage/AzureStorageResultStore.cs index 7636f8901a5..1ff06c07467 100644 --- a/src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Azure/Storage/AzureStorageResultStore.cs +++ b/src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Azure/Storage/AzureStorageResultStore.cs @@ -187,7 +187,7 @@ private static string GetLastSegmentFromPath(string name) => name.Substring(name.LastIndexOf('/') + 1); private static string StripExtension(string name) - => name.Substring(0, name.LastIndexOf(".", StringComparison.Ordinal)); + => name.Substring(0, name.LastIndexOf('.')); private static (string path, bool isDir) GetResultPath( string? executionName = null, diff --git a/src/Libraries/Microsoft.Extensions.AI.Ollama/OllamaChatClient.cs b/src/Libraries/Microsoft.Extensions.AI.Ollama/OllamaChatClient.cs index 727d00f05c8..d3f45358d10 100644 --- a/src/Libraries/Microsoft.Extensions.AI.Ollama/OllamaChatClient.cs +++ b/src/Libraries/Microsoft.Extensions.AI.Ollama/OllamaChatClient.cs @@ -426,7 +426,7 @@ private IEnumerable ToOllamaChatRequestMessages(ChatMe currentTextMessage = new OllamaChatRequestMessage { Role = content.Role.Value, - Content = textContent.Text ?? string.Empty, + Content = textContent.Text, }; break; diff --git a/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs b/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs index 96bd316d746..513ce3652c8 100644 --- a/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs +++ b/src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs @@ -232,6 +232,11 @@ strictObj is bool strictValue ? // Store the tool mode. switch (options.ToolMode) { + case NoneChatToolMode: + runOptions.ToolConstraint = ToolConstraint.None; + break; + + case null: case AutoChatToolMode: runOptions.ToolConstraint = ToolConstraint.Auto; break; diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs index c233ab85b29..fea25191aff 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs @@ -42,7 +42,7 @@ public async Task ToChatResponse_SuccessfullyCreatesResponse(bool useAsync, bool new() { ChoiceIndex = 1, Text = "Hey", ResponseId = "12345", CreatedAt = new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.Zero), ModelId = "model124" }, new() { ChoiceIndex = 0, Text = ", ", AuthorName = "Someone", Role = ChatRole.User, AdditionalProperties = new() { ["a"] = "b" } }, - new() { ChoiceIndex = 1, Text = ", ", AuthorName = "Else", Role = ChatRole.System, AdditionalProperties = new() { ["g"] = "h" } }, + new() { ChoiceIndex = 1, Text = ", ", AuthorName = "Else", Role = ChatRole.System, ChatThreadId = "123", AdditionalProperties = new() { ["g"] = "h" } }, new() { ChoiceIndex = 0, Text = "world!", CreatedAt = new DateTimeOffset(2, 2, 3, 4, 5, 6, TimeSpan.Zero), AdditionalProperties = new() { ["c"] = "d" } }, new() { ChoiceIndex = 1, Text = "you!", Role = ChatRole.Tool, CreatedAt = new DateTimeOffset(3, 2, 3, 4, 5, 6, TimeSpan.Zero), AdditionalProperties = new() { ["e"] = "f", ["i"] = 42 } }, @@ -69,6 +69,8 @@ public async Task ToChatResponse_SuccessfullyCreatesResponse(bool useAsync, bool Assert.Equal(new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.Zero), response.CreatedAt); Assert.Equal("model123", response.ModelId); + Assert.Equal("123", response.ChatThreadId); + Assert.Equal(3, response.Choices.Count); ChatMessage message = response.Choices[0];