From 9e7f5506f4074160d5e5f735ff566d63048f1ec4 Mon Sep 17 00:00:00 2001 From: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com> Date: Mon, 13 Nov 2023 22:13:00 +0000 Subject: [PATCH] .Net: Upgrade .Net notebooks to Microsoft.SemanticKernel, 1.0.0-beta6 (#3478) ### Motivation and Context Ensure .Net notebooks work with Microsoft.SemanticKernel, 1.0.0-beta6 - Replace `WithAzureXXX` with `WithAzureOpenAIXXX` - Replace `new PromptTemplate` with `promptTemplateFactory.Create` ### Contribution Checklist - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone :smile: --- dotnet/notebooks/00-getting-started.ipynb | 4 ++-- .../01-basic-loading-the-kernel.ipynb | 4 ++-- .../02-running-prompts-from-file.ipynb | 4 ++-- .../03-semantic-function-inline.ipynb | 23 +++++++++---------- .../notebooks/04-context-variables-chat.ipynb | 16 +++++-------- dotnet/notebooks/05-using-the-planner.ipynb | 4 ++-- .../notebooks/06-memory-and-embeddings.ipynb | 7 +++--- dotnet/notebooks/07-DALL-E-2.ipynb | 8 +++---- .../notebooks/08-chatGPT-with-DALL-E-2.ipynb | 6 ++--- dotnet/notebooks/09-memory-with-chroma.ipynb | 10 ++++---- .../10-BingSearch-using-kernel.ipynb | 6 ++--- 11 files changed, 43 insertions(+), 49 deletions(-) diff --git a/dotnet/notebooks/00-getting-started.ipynb b/dotnet/notebooks/00-getting-started.ipynb index 597e68c3a3ed..c368dbd0168f 100644 --- a/dotnet/notebooks/00-getting-started.ipynb +++ b/dotnet/notebooks/00-getting-started.ipynb @@ -61,7 +61,7 @@ "outputs": [], "source": [ "// Import Semantic Kernel\n", - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"" + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"" ] }, { @@ -108,7 +108,7 @@ "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "\n", "if (useAzureOpenAI)\n", - " builder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " builder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n", diff --git a/dotnet/notebooks/01-basic-loading-the-kernel.ipynb b/dotnet/notebooks/01-basic-loading-the-kernel.ipynb index 01b143634017..fc0cf4e23dc5 100644 --- a/dotnet/notebooks/01-basic-loading-the-kernel.ipynb +++ b/dotnet/notebooks/01-basic-loading-the-kernel.ipynb @@ -32,7 +32,7 @@ }, "outputs": [], "source": [ - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"" + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"" ] }, { @@ -121,7 +121,7 @@ "outputs": [], "source": [ "Kernel.Builder\n", - ".WithAzureChatCompletionService(\n", + ".WithAzureOpenAIChatCompletionService(\n", " \"my-finetuned-model\", // Azure OpenAI *Deployment Name*\n", " \"https://contoso.openai.azure.com/\", // Azure OpenAI *Endpoint*\n", " \"...your Azure OpenAI Key...\", // Azure OpenAI *Key*\n", diff --git a/dotnet/notebooks/02-running-prompts-from-file.ipynb b/dotnet/notebooks/02-running-prompts-from-file.ipynb index dadfe2466a53..0e9408cff94d 100644 --- a/dotnet/notebooks/02-running-prompts-from-file.ipynb +++ b/dotnet/notebooks/02-running-prompts-from-file.ipynb @@ -91,7 +91,7 @@ }, "outputs": [], "source": [ - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", "\n", "#!import config/Settings.cs\n", "\n", @@ -102,7 +102,7 @@ "// Configure AI backend used by the kernel\n", "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "if (useAzureOpenAI)\n", - " builder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " builder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n", diff --git a/dotnet/notebooks/03-semantic-function-inline.ipynb b/dotnet/notebooks/03-semantic-function-inline.ipynb index d5326783be7b..70fe7ec7bdcb 100644 --- a/dotnet/notebooks/03-semantic-function-inline.ipynb +++ b/dotnet/notebooks/03-semantic-function-inline.ipynb @@ -51,20 +51,21 @@ }, "outputs": [], "source": [ - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", "\n", "#!import config/Settings.cs\n", "\n", "using Microsoft.SemanticKernel;\n", - "using Microsoft.SemanticKernel.SemanticFunctions;\n", "using Microsoft.SemanticKernel.Connectors.AI.OpenAI;\n", + "using Microsoft.SemanticKernel.TemplateEngine;\n", + "using Microsoft.SemanticKernel.TemplateEngine.Basic;\n", "\n", "var builder = new KernelBuilder();\n", "\n", "// Configure AI backend used by the kernel\n", "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "if (useAzureOpenAI)\n", - " builder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " builder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n", @@ -127,8 +128,8 @@ " TopP = 0.5\n", "};\n", "\n", - "var promptConfig = new PromptTemplateConfig();\n", - "promptConfig.ModelSettings.Add(aiRequestSettings);" + "var promptTemplateConfig = new PromptTemplateConfig();\n", + "promptTemplateConfig.ModelSettings.Add(aiRequestSettings);" ] }, { @@ -153,10 +154,10 @@ }, "outputs": [], "source": [ - "var promptTemplate = new PromptTemplate(\n", + "var promptTemplateFactory = new BasicPromptTemplateFactory();\n", + "var promptTemplate = promptTemplateFactory.Create(\n", " skPrompt, // Prompt template defined in natural language\n", - " promptConfig, // Prompt configuration\n", - " kernel // SK instance\n", + " promptTemplateConfig // Prompt configuration\n", ");" ] }, @@ -181,9 +182,7 @@ }, "outputs": [], "source": [ - "var functionConfig = new SemanticFunctionConfig(promptConfig, promptTemplate);\n", - "\n", - "var summaryFunction = kernel.RegisterSemanticFunction(\"MyPlugin\", \"Summary\", functionConfig);" + "var summaryFunction = kernel.RegisterSemanticFunction(\"MyPlugin\", \"Summary\", promptTemplateConfig, promptTemplate);" ] }, { @@ -314,7 +313,7 @@ "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "\n", "if (useAzureOpenAI)\n", - " builder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " builder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n", diff --git a/dotnet/notebooks/04-context-variables-chat.ipynb b/dotnet/notebooks/04-context-variables-chat.ipynb index f5c33f746a9d..1e3e2b8075d9 100644 --- a/dotnet/notebooks/04-context-variables-chat.ipynb +++ b/dotnet/notebooks/04-context-variables-chat.ipynb @@ -34,11 +34,12 @@ }, "outputs": [], "source": [ - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", "#!import config/Settings.cs\n", "\n", "using Microsoft.SemanticKernel;\n", - "using Microsoft.SemanticKernel.SemanticFunctions;\n", + "using Microsoft.SemanticKernel.TemplateEngine;\n", + "using Microsoft.SemanticKernel.TemplateEngine.Basic;\n", "using Microsoft.SemanticKernel.Orchestration;\n", "using Microsoft.SemanticKernel.Connectors.AI.OpenAI;\n", "\n", @@ -47,7 +48,7 @@ "// Configure AI backend used by the kernel\n", "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "if (useAzureOpenAI)\n", - " builder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " builder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n", @@ -91,10 +92,7 @@ " MaxTokens = 2000,\n", " Temperature = 0.7,\n", " TopP = 0.5\n", - "};\n", - "\n", - "var promptConfig = new PromptTemplateConfig();\n", - "promptConfig.ModelSettings.Add(aiRequestSettings);" + "};" ] }, { @@ -121,9 +119,7 @@ }, "outputs": [], "source": [ - "var promptTemplate = new PromptTemplate(skPrompt, promptConfig, kernel);\n", - "var functionConfig = new SemanticFunctionConfig(promptConfig, promptTemplate);\n", - "var chatFunction = kernel.RegisterSemanticFunction(\"ChatBot\", \"Chat\", functionConfig);" + "var chatFunction = kernel.CreateSemanticFunction(skPrompt, requestSettings: aiRequestSettings);" ] }, { diff --git a/dotnet/notebooks/05-using-the-planner.ipynb b/dotnet/notebooks/05-using-the-planner.ipynb index 652884a33773..5b2e459570e5 100644 --- a/dotnet/notebooks/05-using-the-planner.ipynb +++ b/dotnet/notebooks/05-using-the-planner.ipynb @@ -25,7 +25,7 @@ }, "outputs": [], "source": [ - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", "\n", "#!import config/Settings.cs\n", "#!import config/Utils.cs\n", @@ -43,7 +43,7 @@ "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "\n", "if (useAzureOpenAI)\n", - " builder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " builder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n", diff --git a/dotnet/notebooks/06-memory-and-embeddings.ipynb b/dotnet/notebooks/06-memory-and-embeddings.ipynb index 87f957165d75..d03ac6b534c4 100644 --- a/dotnet/notebooks/06-memory-and-embeddings.ipynb +++ b/dotnet/notebooks/06-memory-and-embeddings.ipynb @@ -33,13 +33,12 @@ }, "outputs": [], "source": [ - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", "#r \"nuget: System.Linq.Async, 6.0.1\"\n", "\n", "#!import config/Settings.cs\n", "\n", "using Microsoft.SemanticKernel;\n", - "using Microsoft.SemanticKernel.SemanticFunctions;\n", "using Microsoft.SemanticKernel.Orchestration;\n", "\n", "var kernelBuilder = new KernelBuilder();\n", @@ -48,7 +47,7 @@ "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "\n", "if (useAzureOpenAI)\n", - " kernelBuilder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " kernelBuilder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " kernelBuilder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n", @@ -93,7 +92,7 @@ "\n", "if (useAzureOpenAI)\n", "{\n", - " memoryBuilder.WithAzureTextEmbeddingGenerationService(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n", + " memoryBuilder.WithAzureOpenAITextEmbeddingGenerationService(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n", "}\n", "else\n", "{\n", diff --git a/dotnet/notebooks/07-DALL-E-2.ipynb b/dotnet/notebooks/07-DALL-E-2.ipynb index 8bdd42abde6e..271672cdcafb 100644 --- a/dotnet/notebooks/07-DALL-E-2.ipynb +++ b/dotnet/notebooks/07-DALL-E-2.ipynb @@ -33,7 +33,7 @@ "source": [ "// Usual setup: importing Semantic Kernel SDK and SkiaSharp, used to display images inline.\n", "\n", - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", "#r \"nuget: SkiaSharp, 2.88.3\"\n", "\n", "#!import config/Settings.cs\n", @@ -86,8 +86,8 @@ "\n", "if(useAzureOpenAI)\n", "{\n", - " builder.WithAzureTextEmbeddingGenerationService(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n", - " builder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAITextEmbeddingGenerationService(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", " builder.WithAzureOpenAIImageGenerationService(azureEndpoint, apiKey);\n", "}\n", "else\n", @@ -225,4 +225,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/dotnet/notebooks/08-chatGPT-with-DALL-E-2.ipynb b/dotnet/notebooks/08-chatGPT-with-DALL-E-2.ipynb index 532a7b640f89..5c80e88eee0e 100644 --- a/dotnet/notebooks/08-chatGPT-with-DALL-E-2.ipynb +++ b/dotnet/notebooks/08-chatGPT-with-DALL-E-2.ipynb @@ -56,7 +56,7 @@ "source": [ "// Usual setup: importing Semantic Kernel SDK and SkiaSharp, used to display images inline.\n", "\n", - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", "#r \"nuget: SkiaSharp, 2.88.3\"\n", "\n", "#!import config/Settings.cs\n", @@ -104,7 +104,7 @@ "\n", "if(useAzureOpenAI)\n", "{\n", - " builder.WithAzureChatCompletionService(\"gpt-35-turbo\", azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(\"gpt-35-turbo\", azureEndpoint, apiKey);\n", " builder.WithAzureOpenAIImageGenerationService(azureEndpoint, apiKey);\n", "}\n", "else\n", @@ -240,4 +240,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/dotnet/notebooks/09-memory-with-chroma.ipynb b/dotnet/notebooks/09-memory-with-chroma.ipynb index b2de3f713fdc..e1a0a8878344 100644 --- a/dotnet/notebooks/09-memory-with-chroma.ipynb +++ b/dotnet/notebooks/09-memory-with-chroma.ipynb @@ -38,8 +38,8 @@ }, "outputs": [], "source": [ - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", - "#r \"nuget: Microsoft.SemanticKernel.Connectors.Memory.Chroma, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", + "#r \"nuget: Microsoft.SemanticKernel.Connectors.Memory.Chroma, 1.0.0-beta6\"\n", "#r \"nuget: System.Linq.Async, 6.0.1\"\n", "\n", "#!import config/Settings.cs\n", @@ -59,7 +59,7 @@ "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "\n", "if (useAzureOpenAI)\n", - " kernelBuilder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " kernelBuilder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " kernelBuilder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n", @@ -106,7 +106,7 @@ "\n", "if (useAzureOpenAI)\n", "{\n", - " memoryBuilder.WithAzureTextEmbeddingGenerationService(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n", + " memoryBuilder.WithAzureOpenAITextEmbeddingGenerationService(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n", "}\n", "else\n", "{\n", @@ -465,7 +465,7 @@ "\n", "if (useAzureOpenAI)\n", "{\n", - " memoryBuilder.WithAzureTextEmbeddingGenerationService(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n", + " memoryBuilder.WithAzureOpenAITextEmbeddingGenerationService(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n", "}\n", "else\n", "{\n", diff --git a/dotnet/notebooks/10-BingSearch-using-kernel.ipynb b/dotnet/notebooks/10-BingSearch-using-kernel.ipynb index 17dbafa49f86..72c7839ac9ca 100644 --- a/dotnet/notebooks/10-BingSearch-using-kernel.ipynb +++ b/dotnet/notebooks/10-BingSearch-using-kernel.ipynb @@ -35,8 +35,8 @@ }, "outputs": [], "source": [ - "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta1\"\n", - "#r \"nuget: Microsoft.SemanticKernel.Plugins.Web, 1.0.0-beta1\"\n", + "#r \"nuget: Microsoft.SemanticKernel, 1.0.0-beta6\"\n", + "#r \"nuget: Microsoft.SemanticKernel.Plugins.Web, 1.0.0-beta6\"\n", "\n", "#!import config/Settings.cs\n", "#!import config/Utils.cs\n", @@ -55,7 +55,7 @@ "var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n", "\n", "if (useAzureOpenAI)\n", - " builder.WithAzureChatCompletionService(model, azureEndpoint, apiKey);\n", + " builder.WithAzureOpenAIChatCompletionService(model, azureEndpoint, apiKey);\n", "else\n", " builder.WithOpenAIChatCompletionService(model, apiKey, orgId);\n", "\n",