Skip to content

Commit

Permalink
.Net: Updated dotnet notebooks to use SK v1.0.1 (microsoft#4373)
Browse files Browse the repository at this point in the history
### 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 😄
  • Loading branch information
dmytrostruk authored Dec 19, 2023
1 parent d6a88a6 commit 21038a2
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 48 deletions.
4 changes: 2 additions & 2 deletions dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ requirements and setup instructions.
5. [Using Kernel Arguments to Build a Chat Experience](./notebooks/04-kernel-arguments-chat.ipynb)
6. [Creating and Executing Plans](./notebooks/05-using-the-planner.ipynb)
7. [Building Memory with Embeddings](./notebooks/06-memory-and-embeddings.ipynb)
8. [Creating images with DALL-E 2](./notebooks/07-DALL-E-2.ipynb)
9. [Chatting with ChatGPT and Images](./notebooks/08-chatGPT-with-DALL-E-2.ipynb)
8. [Creating images with DALL-E 3](./notebooks/07-DALL-E-3.ipynb)
9. [Chatting with ChatGPT and Images](./notebooks/08-chatGPT-with-DALL-E-3.ipynb)
10. [BingSearch using Kernel](./notebooks/10-BingSearch-using-kernel.ipynb)

# Nuget packages
Expand Down
2 changes: 1 addition & 1 deletion dotnet/notebooks/00-getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"outputs": [],
"source": [
"// Import Semantic Kernel\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\""
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/notebooks/01-basic-loading-the-kernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\""
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/notebooks/02-running-prompts-from-file.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"\n",
"#!import config/Settings.cs\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion dotnet/notebooks/03-semantic-function-inline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"\n",
"#!import config/Settings.cs\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion dotnet/notebooks/04-kernel-arguments-chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"#!import config/Settings.cs\n",
"\n",
"using Microsoft.SemanticKernel;\n",
Expand Down
4 changes: 2 additions & 2 deletions dotnet/notebooks/05-using-the-planner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Planners.Handlebars, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Planners.Handlebars, 1.0.1-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"#!import config/Utils.cs\n",
Expand Down
7 changes: 4 additions & 3 deletions dotnet/notebooks/06-memory-and-embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Plugins.Memory, 1.0.1-alpha\"\n",
"#r \"nuget: System.Linq.Async, 6.0.1\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand Down Expand Up @@ -87,7 +88,7 @@
"using Microsoft.SemanticKernel.Connectors.OpenAI;\n",
"\n",
"// Memory functionality is experimental\n",
"#pragma warning disable SKEXP0011, SKEXP0052\n",
"#pragma warning disable SKEXP0003, SKEXP0011, SKEXP0052\n",
"\n",
"var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n",
"\n",
Expand Down Expand Up @@ -459,7 +460,7 @@
"outputs": [],
"source": [
"// Memory functionality is experimental\n",
"#pragma warning disable SKEXP0011, SKEXP0052\n",
"#pragma warning disable SKEXP0003, SKEXP0011, SKEXP0052\n",
"\n",
"var memoryBuilder = new MemoryBuilder();\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"source": [
"# Generating images with AI\n",
"\n",
"This notebook demonstrates how to use OpenAI DALL-E 2 to generate images, in combination with other LLM features like text and embedding generation.\n",
"This notebook demonstrates how to use OpenAI DALL-E 3 to generate images, in combination with other LLM features like text and embedding generation.\n",
"\n",
"Here, we use Chat Completion to generate a random image description and DALL-E 2 to create an image from that description, showing the image inline.\n",
"Here, we use Chat Completion to generate a random image description and DALL-E 3 to create an image from that description, showing the image inline.\n",
"\n",
"Lastly, the notebook asks the user to describe the image. The embedding of the user's description is compared to the original description, using Cosine Similarity, and returning a score from 0 to 1, where 1 means exact match."
]
Expand All @@ -33,7 +33,8 @@
"source": [
"// Usual setup: importing Semantic Kernel SDK and SkiaSharp, used to display images inline.\n",
"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"#r \"nuget: System.Numerics.Tensors, 8.0.0\"\n",
"#r \"nuget: SkiaSharp, 2.88.3\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand All @@ -56,7 +57,7 @@
"\n",
"The notebook uses:\n",
"\n",
"* **OpenAI Dall-E 2** to transform the image description into an image\n",
"* **OpenAI Dall-E 3** to transform the image description into an image\n",
"* **text-embedding-ada-002** to compare your guess against the real image description\n",
"\n",
"**Note:**: For Azure OpenAI, your endpoint should have DALL-E API enabled."
Expand Down Expand Up @@ -85,14 +86,14 @@
"// Load OpenAI credentials from config/settings.json\n",
"var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n",
"\n",
"// Configure the three AI features: text embedding (using Ada), text completion (using DaVinci 3), image generation (DALL-E 2)\n",
"// Configure the three AI features: text embedding (using Ada), chat completion, image generation (DALL-E 3)\n",
"var builder = Kernel.CreateBuilder();\n",
"\n",
"if(useAzureOpenAI)\n",
"{\n",
" builder.AddAzureOpenAITextEmbeddingGeneration(\"text-embedding-ada-002\", azureEndpoint, apiKey);\n",
" builder.AddAzureOpenAIChatCompletion(model, azureEndpoint, apiKey);\n",
" builder.AddAzureOpenAITextToImage(azureEndpoint, apiKey);\n",
" builder.AddAzureOpenAITextToImage(\"dall-e-3\", azureEndpoint, apiKey);\n",
"}\n",
"else\n",
"{\n",
Expand All @@ -115,12 +116,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generate a (random) image with DALL-E 2\n",
"# Generate a (random) image with DALL-E 3\n",
"\n",
"**genImgDescription** is a Semantic Function used to generate a random image description. \n",
"The function takes in input a random number to increase the diversity of its output.\n",
"\n",
"The random image description is then given to **Dall-E 2** asking to create an image."
"The random image description is then given to **Dall-E 3** asking to create an image."
]
},
{
Expand Down Expand Up @@ -159,10 +160,10 @@
"var imageDescriptionResult = await kernel.InvokeAsync(genImgDescription, new() { [\"input\"] = random });\n",
"var imageDescription = imageDescriptionResult.ToString();\n",
"\n",
"// Use DALL-E 2 to generate an image. OpenAI in this case returns a URL (though you can ask to return a base64 image)\n",
"var imageUrl = await dallE.GenerateImageAsync(imageDescription.Trim(), 512, 512);\n",
"// Use DALL-E 3 to generate an image. OpenAI in this case returns a URL (though you can ask to return a base64 image)\n",
"var imageUrl = await dallE.GenerateImageAsync(imageDescription.Trim(), 1024, 1024);\n",
"\n",
"await SkiaUtils.ShowImage(imageUrl, 512, 512);"
"await SkiaUtils.ShowImage(imageUrl, 1024, 1024);"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Using ChatGPT with the Semantic Kernel featuring DALL-E 2\n",
"# Using ChatGPT with the Semantic Kernel featuring DALL-E 3\n",
"\n",
"This notebook shows how to make use of the new ChatCompletion API from OpenAI, popularized by ChatGPT. This API brings a new ChatML schema which is different from the TextCompletion API. While the text completion API expects input a prompt and returns a simple string, the chat completion API expects in input a Chat history and returns a new message:\n",
"\n",
Expand Down Expand Up @@ -34,7 +34,7 @@
"source": [
"When deciding between which one to use, know that ChatGPT models (i.e. gpt-3.5-turbo) are optimized for chat applications and have been fine-tuned for instruction-following and dialogue. As such, for creating semantic plugins with the Semantic Kernel, users may still find the TextCompletion model better suited for certain use cases.\n",
"\n",
"The code below shows how to setup SK with ChatGPT, how to manage the Chat history object, and to make things a little more interesting asks ChatGPT to reply with image descriptions instead so we can have a dialog using images, leveraging DALL-E 2 integration."
"The code below shows how to setup SK with ChatGPT, how to manage the Chat history object, and to make things a little more interesting asks ChatGPT to reply with image descriptions instead so we can have a dialog using images, leveraging DALL-E 3 integration."
]
},
{
Expand All @@ -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-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"#r \"nuget: SkiaSharp, 2.88.3\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand All @@ -77,7 +77,7 @@
"The notebook uses:\n",
"\n",
"* **OpenAI ChatGPT** to chat with the user\n",
"* **OpenAI Dall-E 2** to transform messages into images"
"* **OpenAI Dall-E 3** to transform messages into images"
]
},
{
Expand All @@ -103,13 +103,13 @@
"// Load OpenAI credentials from config/settings.json\n",
"var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n",
"\n",
"// Configure the two AI features: OpenAI Chat and DALL-E 2 for image generation\n",
"// Configure the two AI features: OpenAI Chat and DALL-E 3 for image generation\n",
"var builder = Kernel.CreateBuilder();\n",
"\n",
"if(useAzureOpenAI)\n",
"{\n",
" builder.AddAzureOpenAIChatCompletion(\"gpt-35-turbo\", azureEndpoint, apiKey);\n",
" builder.AddAzureOpenAITextToImage(azureEndpoint, apiKey);\n",
" builder.AddAzureOpenAITextToImage(\"dall-e-3\", azureEndpoint, apiKey);\n",
"}\n",
"else\n",
"{\n",
Expand All @@ -135,7 +135,7 @@
"\n",
"Before starting the chat, we create a new chat object with some instructions, which are included in the chat history. \n",
"\n",
"The instructions tell OpenAI what kind of chat we want to have, in this case we ask to reply with \"image descriptions\", so that we can chain ChatGPT with DALL-E 2."
"The instructions tell OpenAI what kind of chat we want to have, in this case we ask to reply with \"image descriptions\", so that we can chain ChatGPT with DALL-E 3."
]
},
{
Expand Down Expand Up @@ -210,8 +210,8 @@
"\n",
" // 3. Show the reply as an image\n",
" Console.WriteLine($\"\\nBot:\");\n",
" var imageUrl = await dallE.GenerateImageAsync(assistantReply.Content, 256, 256);\n",
" await SkiaUtils.ShowImage(imageUrl, 256, 256);\n",
" var imageUrl = await dallE.GenerateImageAsync(assistantReply.Content, 1024, 1024);\n",
" await SkiaUtils.ShowImage(imageUrl, 1024, 1024);\n",
" Console.WriteLine($\"[{assistantReply}]\\n\");\n",
"}"
]
Expand Down
9 changes: 5 additions & 4 deletions dotnet/notebooks/09-memory-with-chroma.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Connectors.Chroma, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Connectors.Chroma, 1.0.1-alpha\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Plugins.Memory, 1.0.1-alpha\"\n",
"#r \"nuget: System.Linq.Async, 6.0.1\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand Down Expand Up @@ -99,7 +100,7 @@
},
"outputs": [],
"source": [
"#pragma warning disable SKEXP0011, SKEXP0022, SKEXP0052\n",
"#pragma warning disable SKEXP0003, SKEXP0011, SKEXP0022, SKEXP0052\n",
"\n",
"using Microsoft.SemanticKernel.Connectors.OpenAI;\n",
"\n",
Expand Down Expand Up @@ -469,7 +470,7 @@
},
"outputs": [],
"source": [
"#pragma warning disable SKEXP0011, SKEXP0022, SKEXP0052\n",
"#pragma warning disable SKEXP0003, SKEXP0011, SKEXP0022, SKEXP0052\n",
"\n",
"var memoryBuilder = new MemoryBuilder();\n",
"\n",
Expand Down
13 changes: 3 additions & 10 deletions dotnet/notebooks/10-BingSearch-using-kernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Plugins.Web, 1.0.0-rc4\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 1.0.1\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Plugins.Web, 1.0.1-alpha\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Plugins.Core, 1.0.1-alpha\"\n",
"\n",
"#!import config/Settings.cs\n",
"#!import config/Utils.cs\n",
Expand Down Expand Up @@ -186,14 +187,6 @@
"}"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Just uncomment the examples to run them in the following code:"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
4 changes: 2 additions & 2 deletions dotnet/notebooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ For a quick dive, look at the [getting started notebook](00-getting-started.ipyn
4. [Using Kernel Arguments to Build a Chat Experience](04-kernel-arguments-chat.ipynb)
5. [Creating and Executing Plans](05-using-the-planner.ipynb)
6. [Building Memory with Embeddings](06-memory-and-embeddings.ipynb)
7. [Creating images with DALL-E 2](07-DALL-E-2.ipynb)
8. [Chatting with ChatGPT and Images](08-chatGPT-with-DALL-E-2.ipynb)
7. [Creating images with DALL-E 3](07-DALL-E-3.ipynb)
8. [Chatting with ChatGPT and Images](08-chatGPT-with-DALL-E-3.ipynb)
9. [Building Semantic Memory with Chroma](09-memory-with-chroma.ipynb)
10. [BingSearch using Kernel](10-BingSearch-using-kernel.ipynb)

Expand Down

0 comments on commit 21038a2

Please sign in to comment.