Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,28 @@ static Task MutateChatHistory(AutoFunctionInvocationContext context, Func<AutoFu
Assert.Contains("\"result\":\"rainy\"", functionResult.GetProperty("content").GetString());
}

[Fact]
public async Task GetChatMessageContentShouldIncludeThinkingWhenPresentInResponseAsync()
{
using var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
{
Content = new StreamContent(File.OpenRead("TestData/chat_completion_with_thinking_response.txt"))
};

this._multiMessageHandlerStub.ResponsesToReturn = [response];

var sut = Kernel.CreateBuilder()
.AddOllamaChatCompletion("test-model", this._httpClient)
.Build()
.GetRequiredService<IChatCompletionService>();

// 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<AutoFunctionInvocationContext, Func<AutoFunctionInvocationContext, Task>, Task> _callback;
Expand Down
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading