diff --git a/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs b/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs index b9a9c62dcbe4..2e066b91869f 100644 --- a/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs +++ b/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs @@ -451,7 +451,7 @@ public static async IAsyncEnumerable InvokeStreamin { yield return toolContent; } - else + else if (detailsUpdate.FunctionOutput != null) { yield return new StreamingChatMessageContent(AuthorRole.Assistant, null) diff --git a/dotnet/src/IntegrationTests/Agents/OpenAIAssistantAgentTests.cs b/dotnet/src/IntegrationTests/Agents/OpenAIAssistantAgentTests.cs index 2bf263b741d3..aa5fcbeef785 100644 --- a/dotnet/src/IntegrationTests/Agents/OpenAIAssistantAgentTests.cs +++ b/dotnet/src/IntegrationTests/Agents/OpenAIAssistantAgentTests.cs @@ -2,6 +2,7 @@ using System; using System.ClientModel; using System.ComponentModel; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,6 +12,8 @@ using Microsoft.SemanticKernel.Agents; using Microsoft.SemanticKernel.Agents.OpenAI; using Microsoft.SemanticKernel.ChatCompletion; +using OpenAI.Files; +using OpenAI.VectorStores; using SemanticKernel.IntegrationTests.TestSettings; using xRetry; using Xunit; @@ -216,6 +219,56 @@ await OpenAIAssistantAgent.CreateAsync( finally { await agent.DeleteThreadAsync(threadId); + await agent.DeleteAsync(); + } + } + + /// + /// Integration test for using function calling + /// and targeting Open AI services. + /// + [Fact] + public async Task AzureOpenAIAssistantAgentStreamingFileSearchAsync() + { + var azureOpenAIConfiguration = this._configuration.GetSection("AzureOpenAI").Get(); + Assert.NotNull(azureOpenAIConfiguration); + + OpenAIClientProvider provider = OpenAIClientProvider.ForAzureOpenAI(new AzureCliCredential(), new Uri(azureOpenAIConfiguration.Endpoint)); + OpenAIAssistantAgent agent = + await OpenAIAssistantAgent.CreateAsync( + provider, + new(azureOpenAIConfiguration.ChatDeploymentName!), + new Kernel()); + + // Upload file - Using a table of fictional employees. + OpenAIFileClient fileClient = provider.Client.GetOpenAIFileClient(); + await using Stream stream = File.OpenRead("TestData/employees.pdf")!; + OpenAIFile fileInfo = await fileClient.UploadFileAsync(stream, "employees.pdf", FileUploadPurpose.Assistants); + + // Create a vector-store + VectorStoreClient vectorStoreClient = provider.Client.GetVectorStoreClient(); + CreateVectorStoreOperation result = + await vectorStoreClient.CreateVectorStoreAsync(waitUntilCompleted: false, + new VectorStoreCreationOptions() + { + FileIds = { fileInfo.Id } + }); + + string threadId = await agent.CreateThreadAsync(); + try + { + await agent.AddChatMessageAsync(threadId, new(AuthorRole.User, "Who works in sales?")); + ChatHistory messages = []; + var chunks = await agent.InvokeStreamingAsync(threadId, messages: messages).ToArrayAsync(); + Assert.NotEmpty(chunks); + Assert.Single(messages); + } + finally + { + await agent.DeleteThreadAsync(threadId); + await agent.DeleteAsync(); + await vectorStoreClient.DeleteVectorStoreAsync(result.VectorStoreId); + await fileClient.DeleteFileAsync(fileInfo.Id); } } diff --git a/dotnet/src/IntegrationTests/IntegrationTests.csproj b/dotnet/src/IntegrationTests/IntegrationTests.csproj index 184653cd8e44..e24215b583d6 100644 --- a/dotnet/src/IntegrationTests/IntegrationTests.csproj +++ b/dotnet/src/IntegrationTests/IntegrationTests.csproj @@ -1,11 +1,11 @@ - + IntegrationTests SemanticKernel.IntegrationTests net8.0 true false - $(NoWarn);CA2007,CA1861,VSTHRD111,SKEXP0001,SKEXP0010,SKEXP0020,SKEXP0040,SKEXP0050,SKEXP0060,SKEXP0070,SKEXP0080,SKEXP0110 + $(NoWarn);CA2007,CA1861,VSTHRD111,SKEXP0001,SKEXP0010,SKEXP0020,SKEXP0040,SKEXP0050,SKEXP0060,SKEXP0070,SKEXP0080,SKEXP0110,OPENAI001 b7762d10-e29b-4bb1-8b74-b6d69a667dd4 @@ -39,7 +39,6 @@ - @@ -179,9 +178,6 @@ Always - - Always - diff --git a/dotnet/src/IntegrationTests/TestData/employees.pdf b/dotnet/src/IntegrationTests/TestData/employees.pdf new file mode 100644 index 000000000000..bba45f80a90b Binary files /dev/null and b/dotnet/src/IntegrationTests/TestData/employees.pdf differ