From 6fd2b347783785495ad4504ef2a5f1ffe4536236 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com>
Date: Fri, 12 Jul 2024 12:14:16 +0100
Subject: [PATCH 1/7] Folders migration
---
dotnet/samples/Concepts/Concepts.csproj | 14 --------------
.../DependencyInjection/Kernel_Injecting.cs | 2 +-
2 files changed, 1 insertion(+), 15 deletions(-)
diff --git a/dotnet/samples/Concepts/Concepts.csproj b/dotnet/samples/Concepts/Concepts.csproj
index 63dabdd45eb6..54e762912108 100644
--- a/dotnet/samples/Concepts/Concepts.csproj
+++ b/dotnet/samples/Concepts/Concepts.csproj
@@ -120,8 +120,6 @@
-
-
@@ -145,11 +143,6 @@
-
-
-
-
-
@@ -231,8 +224,6 @@
-
-
@@ -256,11 +247,6 @@
-
-
-
-
-
diff --git a/dotnet/samples/Concepts/DependencyInjection/Kernel_Injecting.cs b/dotnet/samples/Concepts/DependencyInjection/Kernel_Injecting.cs
index 4c6e38452fc6..21abae070cf0 100644
--- a/dotnet/samples/Concepts/DependencyInjection/Kernel_Injecting.cs
+++ b/dotnet/samples/Concepts/DependencyInjection/Kernel_Injecting.cs
@@ -14,7 +14,7 @@ public async Task RunAsync()
{
ServiceCollection collection = new();
collection.AddLogging(c => c.AddConsole().SetMinimumLevel(LogLevel.Information));
- collection.AddOpenAITextGeneration(TestConfiguration.OpenAI.ModelId, TestConfiguration.OpenAI.ApiKey);
+ collection.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey);
collection.AddSingleton();
// Registering class that uses Kernel to execute a plugin
From 0de1518097af97b21001499e5a77c1f19bcf3dd1 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com>
Date: Fri, 12 Jul 2024 12:34:55 +0100
Subject: [PATCH 2/7] Folders migration
---
dotnet/samples/Concepts/Concepts.csproj | 38 -------------------
.../Functions/FunctionResult_StronglyTyped.cs | 8 ++--
2 files changed, 4 insertions(+), 42 deletions(-)
diff --git a/dotnet/samples/Concepts/Concepts.csproj b/dotnet/samples/Concepts/Concepts.csproj
index 54e762912108..96017e228e4e 100644
--- a/dotnet/samples/Concepts/Concepts.csproj
+++ b/dotnet/samples/Concepts/Concepts.csproj
@@ -143,25 +143,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -247,25 +228,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/dotnet/samples/Concepts/Functions/FunctionResult_StronglyTyped.cs b/dotnet/samples/Concepts/Functions/FunctionResult_StronglyTyped.cs
index 0b50562583ea..79826de22bec 100644
--- a/dotnet/samples/Concepts/Functions/FunctionResult_StronglyTyped.cs
+++ b/dotnet/samples/Concepts/Functions/FunctionResult_StronglyTyped.cs
@@ -2,8 +2,8 @@
using System.Diagnostics;
using System.Text.Json;
-using Azure.AI.OpenAI;
using Microsoft.SemanticKernel;
+using OpenAI.Chat;
namespace Functions;
@@ -79,11 +79,11 @@ public FunctionResultTestDataGen(FunctionResult functionResult, long executionTi
private TokenCounts? ParseTokenCounts()
{
- CompletionsUsage? usage = FunctionResult.Metadata?["Usage"] as CompletionsUsage;
+ var usage = FunctionResult.Metadata?["Usage"] as ChatTokenUsage;
return new TokenCounts(
- completionTokens: usage?.CompletionTokens ?? 0,
- promptTokens: usage?.PromptTokens ?? 0,
+ completionTokens: usage?.OutputTokens ?? 0,
+ promptTokens: usage?.InputTokens ?? 0,
totalTokens: usage?.TotalTokens ?? 0);
}
From 0156c8678993f29a4f2328d2b5810d0bee76c749 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com>
Date: Fri, 12 Jul 2024 12:58:41 +0100
Subject: [PATCH 3/7] Planners.OpenAI migrated, integration tests updated
---
dotnet/samples/Concepts/Concepts.csproj | 58 +------------------
.../Memory/TextChunkingAndEmbedding.cs | 2 +-
...ugin_RecallJsonSerializationWithOptions.cs | 2 +-
.../OpenAIMemoryBuilderExtensions.cs | 44 ++++++++++++++
.../Connectors/OpenAI/OpenAIToolsTests.cs | 3 +-
.../IntegrationTests/IntegrationTests.csproj | 12 +++-
.../Planners.OpenAI/Planners.OpenAI.csproj | 2 +-
.../FunctionCallingStepwisePlanner.cs | 4 +-
8 files changed, 62 insertions(+), 65 deletions(-)
create mode 100644 dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs
diff --git a/dotnet/samples/Concepts/Concepts.csproj b/dotnet/samples/Concepts/Concepts.csproj
index 96017e228e4e..a11241024bf9 100644
--- a/dotnet/samples/Concepts/Concepts.csproj
+++ b/dotnet/samples/Concepts/Concepts.csproj
@@ -73,7 +73,7 @@
-
+
@@ -143,34 +143,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -228,34 +200,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs b/dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs
index 013bb4961621..96b3cb9431db 100644
--- a/dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs
+++ b/dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.ML.Tokenizers;
-using Microsoft.SemanticKernel.Connectors.OpenAI;
+using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using Microsoft.SemanticKernel.Text;
namespace Memory;
diff --git a/dotnet/samples/Concepts/Memory/TextMemoryPlugin_RecallJsonSerializationWithOptions.cs b/dotnet/samples/Concepts/Memory/TextMemoryPlugin_RecallJsonSerializationWithOptions.cs
index fbc313adebf4..883195b68df9 100644
--- a/dotnet/samples/Concepts/Memory/TextMemoryPlugin_RecallJsonSerializationWithOptions.cs
+++ b/dotnet/samples/Concepts/Memory/TextMemoryPlugin_RecallJsonSerializationWithOptions.cs
@@ -4,7 +4,7 @@
using System.Text.Json;
using System.Text.Unicode;
using Microsoft.SemanticKernel;
-using Microsoft.SemanticKernel.Connectors.OpenAI;
+using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Plugins.Memory;
diff --git a/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs b/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs
new file mode 100644
index 000000000000..2f6b94b8362d
--- /dev/null
+++ b/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs
@@ -0,0 +1,44 @@
+// Copyright (c) Microsoft. All rights reserved.
+
+using System.Diagnostics.CodeAnalysis;
+using System.Net.Http;
+using Microsoft.SemanticKernel.Http;
+using Microsoft.SemanticKernel.Memory;
+
+namespace Microsoft.SemanticKernel.Connectors.OpenAI;
+
+///
+/// Provides extension methods for the class to configure OpenAI and AzureOpenAI connectors.
+///
+public static class OpenAIMemoryBuilderExtensions
+{
+ ///
+ /// Adds the OpenAI text embeddings service.
+ /// See https://platform.openai.com/docs for service details.
+ ///
+ /// The instance
+ /// OpenAI model name, see https://platform.openai.com/docs/models
+ /// OpenAI API key, see https://platform.openai.com/account/api-keys
+ /// OpenAI organization id. This is usually optional unless your account belongs to multiple organizations.
+ /// Custom for HTTP requests.
+ /// The number of dimensions the resulting output embeddings should have. Only supported in "text-embedding-3" and later models.
+ /// Self instance
+ [Experimental("SKEXP0010")]
+ public static MemoryBuilder WithOpenAITextEmbeddingGeneration(
+ this MemoryBuilder builder,
+ string modelId,
+ string apiKey,
+ string? orgId = null,
+ HttpClient? httpClient = null,
+ int? dimensions = null)
+ {
+ return builder.WithTextEmbeddingGeneration((loggerFactory, builderHttpClient) =>
+ new OpenAITextEmbeddingGenerationService(
+ modelId,
+ apiKey,
+ orgId,
+ HttpClientProvider.GetHttpClient(httpClient ?? builderHttpClient),
+ loggerFactory,
+ dimensions));
+ }
+}
diff --git a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAIToolsTests.cs b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAIToolsTests.cs
index 049287fbbc14..243526fdfc82 100644
--- a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAIToolsTests.cs
+++ b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAIToolsTests.cs
@@ -13,7 +13,6 @@
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
-using SemanticKernel.IntegrationTests.Planners.Stepwise;
using SemanticKernel.IntegrationTests.TestSettings;
using Xunit;
@@ -740,7 +739,7 @@ private Kernel InitializeKernel(bool importHelperPlugin = false)
.AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(path: "testsettings.development.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
- .AddUserSecrets()
+ .AddUserSecrets()
.Build();
///
diff --git a/dotnet/src/IntegrationTests/IntegrationTests.csproj b/dotnet/src/IntegrationTests/IntegrationTests.csproj
index df5afa473ce7..09ae7be3d3b6 100644
--- a/dotnet/src/IntegrationTests/IntegrationTests.csproj
+++ b/dotnet/src/IntegrationTests/IntegrationTests.csproj
@@ -17,7 +17,10 @@
+
+
+
@@ -75,8 +78,9 @@
+
-
+
@@ -151,6 +155,12 @@
+
+
+
+
+
+
Always
diff --git a/dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj b/dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj
index 194753a700ad..d6f5f1bb08e1 100644
--- a/dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj
+++ b/dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj
@@ -32,7 +32,7 @@
-
+
diff --git a/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs b/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs
index 5deb0c5dbd20..4a6508ff3339 100644
--- a/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs
+++ b/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs
@@ -136,7 +136,7 @@ private async Task ExecuteCoreAsync(
// Look up function in kernel
foreach (OpenAIFunctionToolCall functionResponse in functionResponses)
{
- if (clonedKernel.Plugins.TryGetFunctionAndArguments(functionResponse, out KernelFunction? pluginFunction, out KernelArguments? arguments))
+ if (clonedKernel.Plugins.TryGetOpenAIFunctionAndArguments(functionResponse, out KernelFunction? pluginFunction, out KernelArguments? arguments))
{
try
{
@@ -231,7 +231,7 @@ private bool TryGetFunctionResponse(ChatMessageContent chatMessage, [NotNullWhen
errorMessage = null;
try
{
- functionResponses = openAiChatMessage.GetOpenAIFunctionToolCalls();
+ functionResponses = openAiChatMessage.GetFunctionToolCalls();
}
catch (JsonException)
{
From b4a4caa111397d0172bc1e9023907919311df6c0 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com>
Date: Fri, 12 Jul 2024 13:08:17 +0100
Subject: [PATCH 4/7] Ensure builds
---
.../samples/LearnResources/LearnResources.csproj | 5 +++--
.../LearnResources/MicrosoftLearn/AIServices.cs | 14 --------------
2 files changed, 3 insertions(+), 16 deletions(-)
diff --git a/dotnet/samples/LearnResources/LearnResources.csproj b/dotnet/samples/LearnResources/LearnResources.csproj
index d210f8effa91..72cff80ad017 100644
--- a/dotnet/samples/LearnResources/LearnResources.csproj
+++ b/dotnet/samples/LearnResources/LearnResources.csproj
@@ -51,7 +51,8 @@
-
+
+
@@ -68,6 +69,6 @@
-
+
\ No newline at end of file
diff --git a/dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs b/dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs
index a56e6591f8ad..d957358cac77 100644
--- a/dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs
+++ b/dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs
@@ -45,25 +45,11 @@ public async Task RunAsync()
.Build();
//
- // You could instead create a kernel with a legacy Azure OpenAI text completion service
- //
- kernel = Kernel.CreateBuilder()
- .AddAzureOpenAITextGeneration(textModelId, endpoint, apiKey)
- .Build();
- //
-
// You can also create a kernel with a (non-Azure) OpenAI chat completion service
//
kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(openAImodelId, openAIapiKey)
.Build();
//
-
- // Or a kernel with a legacy OpenAI text completion service
- //
- kernel = Kernel.CreateBuilder()
- .AddOpenAITextGeneration(openAItextModelId, openAIapiKey)
- .Build();
- //
}
}
From d0e26679f4d7efe6a8612df37a7706830934e372 Mon Sep 17 00:00:00 2001
From: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
Date: Fri, 12 Jul 2024 16:39:24 +0100
Subject: [PATCH 5/7] Update
dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs
---
.../Extensions/OpenAIMemoryBuilderExtensions.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs b/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs
index 2f6b94b8362d..0ac425a15593 100644
--- a/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs
+++ b/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs
@@ -8,7 +8,7 @@
namespace Microsoft.SemanticKernel.Connectors.OpenAI;
///
-/// Provides extension methods for the class to configure OpenAI and AzureOpenAI connectors.
+/// Provides extension methods for the class to configure OpenAI connector.
///
public static class OpenAIMemoryBuilderExtensions
{
From 8e86cb5b9de57b8471ae75f17cd8afb9544882ae Mon Sep 17 00:00:00 2001
From: SergeyMenshykh
Date: Fri, 12 Jul 2024 16:40:48 +0100
Subject: [PATCH 6/7] fix: revert unnecessary breaking changes
---
.../Stepwise/FunctionCallingStepwisePlanner.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs b/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs
index 4a6508ff3339..5deb0c5dbd20 100644
--- a/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs
+++ b/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs
@@ -136,7 +136,7 @@ private async Task ExecuteCoreAsync(
// Look up function in kernel
foreach (OpenAIFunctionToolCall functionResponse in functionResponses)
{
- if (clonedKernel.Plugins.TryGetOpenAIFunctionAndArguments(functionResponse, out KernelFunction? pluginFunction, out KernelArguments? arguments))
+ if (clonedKernel.Plugins.TryGetFunctionAndArguments(functionResponse, out KernelFunction? pluginFunction, out KernelArguments? arguments))
{
try
{
@@ -231,7 +231,7 @@ private bool TryGetFunctionResponse(ChatMessageContent chatMessage, [NotNullWhen
errorMessage = null;
try
{
- functionResponses = openAiChatMessage.GetFunctionToolCalls();
+ functionResponses = openAiChatMessage.GetOpenAIFunctionToolCalls();
}
catch (JsonException)
{
From fcb73dd6c86a402ee64fd36150a0a97342e390a1 Mon Sep 17 00:00:00 2001
From: SergeyMenshykh
Date: Tue, 16 Jul 2024 12:14:51 +0100
Subject: [PATCH 7/7] fix: enable handlebars planner integration tests
---
dotnet/src/IntegrationTests/IntegrationTests.csproj | 4 ----
1 file changed, 4 deletions(-)
diff --git a/dotnet/src/IntegrationTests/IntegrationTests.csproj b/dotnet/src/IntegrationTests/IntegrationTests.csproj
index 09ae7be3d3b6..6d741d390c2e 100644
--- a/dotnet/src/IntegrationTests/IntegrationTests.csproj
+++ b/dotnet/src/IntegrationTests/IntegrationTests.csproj
@@ -17,8 +17,6 @@
-
-
@@ -156,8 +154,6 @@
-
-