{"id":1551,"date":"2023-11-13T16:15:03","date_gmt":"2023-11-14T00:15:03","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=1551"},"modified":"2024-01-10T15:09:33","modified_gmt":"2024-01-10T23:09:33","slug":"introducing-v1-0-0-beta6-for-the-net-semantic-kernel-sdk","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/introducing-v1-0-0-beta6-for-the-net-semantic-kernel-sdk\/","title":{"rendered":"Introducing v1.0.0 Beta6 for the .NET Semantic Kernel SDK"},"content":{"rendered":"<blockquote><p>Semantic Kernel <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/releases\/tag\/dotnet-1.0.1\">v1.0<\/a> has shipped and the contents of this blog entry is now out of date.<\/p><\/blockquote>\n<p>The Semantic Kernel team continues to make improvements to our beta release of the .NET library. <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.SemanticKernel\/1.0.0-beta6\">Our sixth Beta release<\/a> is the most jam packed one so far, so we wanted to take the opportunity to share everything new inside of it.<\/p>\n<p>As a reminder, if you want visibility into our <em>full<\/em> plans for v1 of Semantic Kernel, please check out <a href=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/what-to-expect-from-v1-and-beyond-for-semantic-kernel\/\">this blog post<\/a>. Additionally, if you\u2019re needing to update from pre-Beta, we recommend our <a href=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/introducing-the-v1-0-0-beta1-for-the-net-semantic-kernel-sdk\/\">first Beta blog post<\/a> where we outline some of the initial breaking changes.<\/p>\n<h2 style=\"margin-top: 1em;\">Semantic functions are getting <em>way<\/em> more powerful.<\/h2>\n<p>With this release, we\u2019ve made to substantial improvements to how semantic functions work. We now have Handlebars support out-of-the-box <em>and<\/em> you can start authoring semantic functions that take full control of the chat completion API.<\/p>\n<h3 style=\"margin-top: 1em;\">Initial Handlebars support (with extensibility for more!)<\/h3>\n<p>With Semantic Kernel, we already provided an out-of-the-box template engine. We heard from the community, however, that this template engine was too limiting, so with Beta6 we\u2019re now adding support for Handlebars.<\/p>\n<pre>var templateFactory = new HandlebarsPromptTemplateFactory();\r\nvar handlebarsPrompt = \"Hello AI, my name is {{name}}. What is the origin of my name?\";\r\n\r\n\r\n\/\/ Create the semantic function with Handlebars\r\nvar skfunction = kernel.CreateSemanticFunction(\r\n    promptTemplate: prompt,\r\n    functionName: \"MyFunction\",\r\n    promptTemplateConfig: new PromptTemplateConfig()\r\n    {\r\n        TemplateFormat = templateFormat\r\n    },\r\n    promptTemplateFactory:\r\n);\r\n\r\n\/\/ Create your variables\r\nvar variables = new ContextVariables()\r\n{\r\n    { \"name\", \"Bob\" }\r\n};\r\n\r\n\/\/ Run your semantic function\r\nvar result = await kernel.RunAsync(skfunction, variables);<\/pre>\n<p>If you have a different templating language that you favor (e.g., Jinja2, Liquid, etc.), we also used this release to update how you can author and use templating languages. You can follow the patterns we set while creating our new <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/src\/Extensions\/TemplateEngine.Handlebars\/HandlebarsPromptTemplateFactory.cs\">HandlebarsPromptTemplateFactory<\/a> class to add support for <em>any<\/em> template language. Afterwards, you can use it to create new semantic functions.<\/p>\n<p>Lastly, our approach to adding template engines also allows you to use prompts with multiple different template engines all in the same kernel! No need to refactor prompts that you\u2019ve collected from other prompt repositories to bring them into your AI application. To see an example of this in action, check out <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/KernelSyntaxExamples\/Example64_MultiplePromptTemplates.cs\">example 64 in our kernel syntax examples<\/a>.<\/p>\n<h3 style=\"margin-top: 1em;\">Chat role support in semantic functions<\/h3>\n<p>One of the biggest limiting factors of semantic functions was that you couldn\u2019t leverage different messages or roles while using chat completion APIs. This changes with the introduction of a new prompt syntax that we\u2019re introducing that will work across<em> all<\/em> model types.<\/p>\n<p>We\u2019re starting today with just the new &lt;message \/&gt; tag. With it, you\u2019ll be able to create prompts like the following:<\/p>\n<pre class=\"prettyprint language-html\"><code class=\"language-html\">&lt;message role=\"user\"&gt;Can you tell me about Seattle?&lt;\/message&gt;\r\n&lt;message role=\"system\"&gt;Respond to the user request in JSON&lt;\/message&gt;<\/code><\/pre>\n<p>This is powerful, because it means you can quickly and easily author prompts with system messages at the top <em>and<\/em> bottom of your prompt to better control the behavior of the AI. Behind the scenes, we\u2019ll parse these tags and turn them into a chat history object for you.<\/p>\n<p>In the near future, we\u2019ll also use these tags to support multi-modal applications. For example, if you wanted to add an image to a message, you\u2019d be able to use the &lt;img\/&gt; tag straight from HTML! The same will be true for other file types like audio and video.<\/p>\n<pre class=\"prettyprint language-html\"><code class=\"language-html\">&lt;message role=\"user\"&gt;Can you describe this image?&lt;img src=\".\/cat.png\"\/&gt;&lt;\/message&gt;<\/code><\/pre>\n<h2 style=\"margin-top: 1em;\">We now have full OpenAI function calling support.<\/h2>\n<p>Semantic Kernel has had function calling support with Open AI for awhile, but it wasn\u2019t possible to add the results of a function call back into the chat history to facilitate long running conversations. With Beta6, that is now possible with the new AddFunctionMessage method on Chat History.<\/p>\n<p>To see function calling working end-to-end, we recommend checking out <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/KernelSyntaxExamples\/Example59_OpenAIFunctionCalling.cs\">example 59 in our kernel syntax examples<\/a>. In it, we highlight the following:<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>Use a kernel to automatically add functions to the OpenAI function calling request.<\/li>\n<li>Take the response from OpenAI to invoke a function with the kernel.<\/li>\n<li>Use the results of the function to create a new function message in the chat history.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>To make function calling even easier, we\u2019re currently updating our implementation of stepwise planner to leverage it. Keep an eye out for it in out next release!<\/p>\n<h2 style=\"margin-top: 1em;\">Monitor your functions with hooks.<\/h2>\n<p>For enterprises, it\u2019s extremely important to know what your AI applications are doing every step of the process. To provide this visibility, we\u2019ve introduced pre- and post-hooks that run for every SKFunction, which allows you to do the following things:<\/p>\n<ul>\n<li>Generate telemetry for your functions.<\/li>\n<li>Provide updates to users on the progress of long-running tasks.<\/li>\n<li>Add logic that enforces responsible AI.<\/li>\n<\/ul>\n<p>For example, if you want to inspect rendered prompts before they are sent to the AI to check that users don\u2019t accidentally send passwords, you could write something like the following:<\/p>\n<pre>kernel.FunctionInvoking += (object? sender, FunctionInvokingEventArgs e) =&gt;\r\n    {\r\n        if (e.TryGetRenderedPrompt(out var prompt) &amp;&amp; credScanModule.ScanCredentials(prompt!).Any())\r\n        {\r\n            var redactedPrompt = credScanModule.RemoveCredentials(prompt!);\r\n            e.TryUpdateRenderedPrompt(redactedPrompt);\r\n            \r\n            Console.WriteLine(\"Credentials detected and redacted from the prompt.\");\r\n            Console.WriteLine($\"Updated prompt: {redactedPrompt}\");\r\n        }\r\n    };<\/pre>\n<p>This code adds a hook whenever a function is invoked so that the rendered prompt can be investigated. If a credential is detected, the prompt can be altered so that the password is no longer sent to the LLM. You also can cancel the entire function if you wanted.<\/p>\n<p>To see additional scenarios and examples on how to use both pre- and post- hooks, please refer to <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/KernelSyntaxExamples\/Example57_KernelHooks.cs\">example 57 of the kernel syntax examples<\/a>.<\/p>\n<h2 style=\"margin-top: 1em;\">What\u2019s next?<\/h2>\n<p>As part of Ignite this week, we\u2019ll be merging in several other updates that improve the quality of Semantic Kernel. In particular, keep your eyes peeled for planner improvements that leverage our new Handlebars support and function calling support.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Semantic Kernel v1.0 has shipped and the contents of this blog entry is now out of date. The Semantic Kernel team continues to make improvements to our beta release of the .NET library. Our sixth Beta release is the most jam packed one so far, so we wanted to take the opportunity to share everything [&hellip;]<\/p>\n","protected":false},"author":121401,"featured_media":1558,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-semantic-kernel"],"acf":[],"blog_post_summary":"<p>Semantic Kernel v1.0 has shipped and the contents of this blog entry is now out of date. The Semantic Kernel team continues to make improvements to our beta release of the .NET library. Our sixth Beta release is the most jam packed one so far, so we wanted to take the opportunity to share everything [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/1551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/users\/121401"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=1551"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/1551\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/1558"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=1551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=1551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=1551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}