diff --git a/dotnet/src/Connectors/Connectors.Ollama.UnitTests/Services/OllamaChatCompletionTests.cs b/dotnet/src/Connectors/Connectors.Ollama.UnitTests/Services/OllamaChatCompletionTests.cs index 57870c427674..cd31cc47b518 100644 --- a/dotnet/src/Connectors/Connectors.Ollama.UnitTests/Services/OllamaChatCompletionTests.cs +++ b/dotnet/src/Connectors/Connectors.Ollama.UnitTests/Services/OllamaChatCompletionTests.cs @@ -767,6 +767,28 @@ static Task MutateChatHistory(AutoFunctionInvocationContext context, Func(); + + // Act + var result = await sut.GetChatMessageContentAsync("test prompt"); + + // Assert + Assert.Contains("This is reasoning content", result.Content); + } + private sealed class AutoFunctionInvocationFilter : IAutoFunctionInvocationFilter { private readonly Func, Task> _callback; diff --git a/dotnet/src/Connectors/Connectors.Ollama.UnitTests/TestData/chat_completion_with_thinking_response.txt b/dotnet/src/Connectors/Connectors.Ollama.UnitTests/TestData/chat_completion_with_thinking_response.txt new file mode 100644 index 000000000000..147f728a480c --- /dev/null +++ b/dotnet/src/Connectors/Connectors.Ollama.UnitTests/TestData/chat_completion_with_thinking_response.txt @@ -0,0 +1,2 @@ +{"model":"qwen3:0.6b","message":{"role":"assistant","content":"Final answer","thinking":"This is reasoning content"},"done":false} +{"model":"qwen3:0.6b","message":{"role":"assistant","content":"","thinking":""},"done":true} \ No newline at end of file diff --git a/dotnet/src/InternalUtilities/meai/Extensions/ChatMessageExtensions.cs b/dotnet/src/InternalUtilities/meai/Extensions/ChatMessageExtensions.cs index b82bfb61f577..a69a1bb6446c 100644 --- a/dotnet/src/InternalUtilities/meai/Extensions/ChatMessageExtensions.cs +++ b/dotnet/src/InternalUtilities/meai/Extensions/ChatMessageExtensions.cs @@ -23,6 +23,24 @@ internal static ChatMessageContent ToChatMessageContent(this ChatMessage message Role = new AuthorRole(message.Role.Value), }; + if (response?.RawRepresentation is not null) + { + var raw = response.RawRepresentation; + var messageProp = raw.GetType().GetProperty("Message"); + var messageObj = messageProp?.GetValue(raw); + var thinkingProp = messageObj?.GetType().GetProperty("Thinking"); + var thinking = thinkingProp?.GetValue(messageObj) as string; + + if (!string.IsNullOrWhiteSpace(thinking)) + { + result.Items.Add(new Microsoft.SemanticKernel.TextContent($"[THINKING]\n{thinking}") + { + ModelId = response?.ModelId, + InnerContent = raw + }); + } + } + foreach (AIContent content in message.Contents) { #pragma warning disable SKEXP0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.