From b18b55b39d65c03b173cb6b2b9672076d62f01f3 Mon Sep 17 00:00:00 2001 From: Chris Rickman Date: Tue, 25 Jun 2024 10:59:02 -0700 Subject: [PATCH 1/3] Fixed --- .../Connectors.OpenAI/AzureSdk/ClientCore.cs | 19 +++++++++++++------ .../OpenAI/OpenAICompletionTests.cs | 5 +++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs b/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs index 8059077d8bf4..78d2d2028cc0 100644 --- a/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs +++ b/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs @@ -693,15 +693,22 @@ internal async IAsyncEnumerable GetStreamingC OpenAIFunctionToolCall.TrackStreamingToolingUpdate(update.ToolCallUpdate, ref toolCallIdsByIndex, ref functionNamesByIndex, ref functionArgumentBuildersByIndex); } - var openAIStreamingChatMessageContent = new OpenAIStreamingChatMessageContent(update, update.ChoiceIndex ?? 0, this.DeploymentOrModelName, metadata) { AuthorName = streamedName }; + AuthorRole? role = null; + if (streamedRole.HasValue) + { + role = new AuthorRole(streamedRole.Value.ToString()); + } + + OpenAIStreamingChatMessageContent openAIStreamingChatMessageContent = new(update, update.ChoiceIndex ?? 0, this.DeploymentOrModelName, metadata) { AuthorName = streamedName, Role = role, }; if (update.ToolCallUpdate is StreamingFunctionToolCallUpdate functionCallUpdate) { - openAIStreamingChatMessageContent.Items.Add(new StreamingFunctionCallUpdateContent( - callId: functionCallUpdate.Id, - name: functionCallUpdate.Name, - arguments: functionCallUpdate.ArgumentsUpdate, - functionCallIndex: functionCallUpdate.ToolCallIndex)); + openAIStreamingChatMessageContent.Items.Add( + new StreamingFunctionCallUpdateContent( + callId: functionCallUpdate.Id, + name: functionCallUpdate.Name, + arguments: functionCallUpdate.ArgumentsUpdate, + functionCallIndex: functionCallUpdate.ToolCallIndex)); } streamedContents?.Add(openAIStreamingChatMessageContent); diff --git a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs index 03cd3429d4b0..675661b76d83 100644 --- a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs +++ b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs @@ -128,6 +128,11 @@ public async Task AzureOpenAIStreamingTestAsync(bool useChatModel, string prompt // Act await foreach (var content in target.InvokeStreamingAsync(plugins["ChatPlugin"]["Chat"], new() { [InputParameterName] = prompt })) { + if (content is StreamingChatMessageContent messageContent) + { + Assert.NotNull(messageContent.Role); + } + fullResult.Append(content); } From 34ca63e5a19afab093ea0a84e445365ea211031c Mon Sep 17 00:00:00 2001 From: Chris Rickman Date: Tue, 25 Jun 2024 11:08:03 -0700 Subject: [PATCH 2/3] Formatting --- .../Connectors.OpenAI/AzureSdk/ClientCore.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs b/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs index 78d2d2028cc0..06f6c3707c5b 100644 --- a/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs +++ b/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs @@ -703,12 +703,11 @@ internal async IAsyncEnumerable GetStreamingC if (update.ToolCallUpdate is StreamingFunctionToolCallUpdate functionCallUpdate) { - openAIStreamingChatMessageContent.Items.Add( - new StreamingFunctionCallUpdateContent( - callId: functionCallUpdate.Id, - name: functionCallUpdate.Name, - arguments: functionCallUpdate.ArgumentsUpdate, - functionCallIndex: functionCallUpdate.ToolCallIndex)); + openAIStreamingChatMessageContent.Items.Add(new StreamingFunctionCallUpdateContent( + callId: functionCallUpdate.Id, + name: functionCallUpdate.Name, + arguments: functionCallUpdate.ArgumentsUpdate, + functionCallIndex: functionCallUpdate.ToolCallIndex)); } streamedContents?.Add(openAIStreamingChatMessageContent); From 0282c72497b41227480d139dbb684579cb08bef5 Mon Sep 17 00:00:00 2001 From: Chris Rickman Date: Tue, 25 Jun 2024 11:08:40 -0700 Subject: [PATCH 3/3] Final format --- .../Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs b/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs index 06f6c3707c5b..fa42388d74cd 100644 --- a/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs +++ b/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs @@ -699,7 +699,12 @@ internal async IAsyncEnumerable GetStreamingC role = new AuthorRole(streamedRole.Value.ToString()); } - OpenAIStreamingChatMessageContent openAIStreamingChatMessageContent = new(update, update.ChoiceIndex ?? 0, this.DeploymentOrModelName, metadata) { AuthorName = streamedName, Role = role, }; + OpenAIStreamingChatMessageContent openAIStreamingChatMessageContent = + new(update, update.ChoiceIndex ?? 0, this.DeploymentOrModelName, metadata) + { + AuthorName = streamedName, + Role = role, + }; if (update.ToolCallUpdate is StreamingFunctionToolCallUpdate functionCallUpdate) {