Skip to content

Commit d717580

Browse files
authored
.Net Fix - Include role definition for each StreamingChatMessageContent (microsoft#6957)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> `StreamingChatMessageContent.AuthorRole` always `null` ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Logic already exists to capture role, but it was not being passed to each and every instance of StreamingChatMessageContent. Other properties, such as `ModelId` are included with each and every instance. Updated integration test. Issue: microsoft#6952 ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄
1 parent e53c192 commit d717580

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,18 @@ internal async IAsyncEnumerable<OpenAIStreamingChatMessageContent> GetStreamingC
693693
OpenAIFunctionToolCall.TrackStreamingToolingUpdate(update.ToolCallUpdate, ref toolCallIdsByIndex, ref functionNamesByIndex, ref functionArgumentBuildersByIndex);
694694
}
695695

696-
var openAIStreamingChatMessageContent = new OpenAIStreamingChatMessageContent(update, update.ChoiceIndex ?? 0, this.DeploymentOrModelName, metadata) { AuthorName = streamedName };
696+
AuthorRole? role = null;
697+
if (streamedRole.HasValue)
698+
{
699+
role = new AuthorRole(streamedRole.Value.ToString());
700+
}
701+
702+
OpenAIStreamingChatMessageContent openAIStreamingChatMessageContent =
703+
new(update, update.ChoiceIndex ?? 0, this.DeploymentOrModelName, metadata)
704+
{
705+
AuthorName = streamedName,
706+
Role = role,
707+
};
697708

698709
if (update.ToolCallUpdate is StreamingFunctionToolCallUpdate functionCallUpdate)
699710
{

dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs

+5
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public async Task AzureOpenAIStreamingTestAsync(bool useChatModel, string prompt
128128
// Act
129129
await foreach (var content in target.InvokeStreamingAsync<StreamingKernelContent>(plugins["ChatPlugin"]["Chat"], new() { [InputParameterName] = prompt }))
130130
{
131+
if (content is StreamingChatMessageContent messageContent)
132+
{
133+
Assert.NotNull(messageContent.Role);
134+
}
135+
131136
fullResult.Append(content);
132137
}
133138

0 commit comments

Comments
 (0)