{"id":2625,"date":"2024-05-20T08:14:49","date_gmt":"2024-05-20T15:14:49","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=2625"},"modified":"2024-05-20T11:19:58","modified_gmt":"2024-05-20T18:19:58","slug":"use-semantic-kernel-to-create-a-restaurant-bookings-sample-with-net","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/use-semantic-kernel-to-create-a-restaurant-bookings-sample-with-net\/","title":{"rendered":"Use Semantic Kernel to create a Restaurant Bookings Sample with .NET"},"content":{"rendered":"<p>Hi all,<\/p>\n<p>With Microsoft Build approaching, we wanted to share some walk throughs and samples of Semantic Kernel. Today we&#8217;re going to dive into a <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/main\/dotnet\/samples\/Demos\/BookingRestaurant\">Restaurant booking sample<\/a> to showcase multiple features of Semantic Kernel.<\/p>\n<p>This\u00a0sample\u00a0provides\u00a0a\u00a0practical\u00a0demonstration\u00a0of\u00a0how\u00a0to leverage\u00a0features\u00a0from the\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/semantic-kernel\">Semantic Kernel<\/a>\u00a0to build a\u00a0console\u00a0application. Specifically, the application utilizes the\u00a0<a href=\"https:\/\/www.microsoft.com\/en-us\/microsoft-365\/business\/scheduling-and-booking-app\">Business Schedule and\u00a0Booking\u00a0API<\/a>\u00a0through\u00a0Microsoft\u00a0Graph\u00a0to\u00a0enable\u00a0a Large Language Model (LLM) to book restaurant appointments efficiently. This guide will walk you\u00a0through\u00a0the\u00a0necessary\u00a0steps\u00a0to integrate these technologies seamlessly.<\/p>\n<p><strong>Semantic Kernel Features\u00a0Used<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/src\/SemanticKernel.Abstractions\/Functions\/KernelPlugin.cs\">Plugin<\/a>\u00a0&#8211; Creating a Plugin from a native C# Booking class to be used by the Kernel to\u00a0interact\u00a0with\u00a0Bookings\u00a0API.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/src\/SemanticKernel.Abstractions\/AI\/ChatCompletion\/IChatCompletionService.cs\">Chat Completion Service<\/a>\u00a0&#8211; Using the Chat Completion Service\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/src\/Connectors\/Connectors.OpenAI\/ChatCompletion\/OpenAIChatCompletionService.cs\">OpenAI Connector implementation<\/a>\u00a0to\u00a0generate\u00a0responses from the LLM.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/src\/SemanticKernel.Abstractions\/AI\/ChatCompletion\/ChatHistory.cs\">Chat History<\/a>\u00a0Using the Chat History abstraction to create, update and retrieve chat history from Chat Completion Models.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/KernelSyntaxExamples\/Example59_OpenAIFunctionCalling.cs\">Auto Function Calling<\/a>\u00a0Enables the LLM to have knowledge of current importedUsing the Function Calling\u00a0feature\u00a0automatically call the Booking Plugin from the LLM.<\/li>\n<\/ul>\n<p><strong>Prerequisites<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/dotnet.microsoft.com\/download\/dotnet\/8.0\">.NET 8<\/a>.<\/li>\n<li><a href=\"https:\/\/www.microsoft.com\/en-us\/microsoft-365\/business\/compare-all-microsoft-365-business-products\">Microsoft 365 Business License<\/a>\u00a0to use\u00a0<a href=\"https:\/\/www.microsoft.com\/en-us\/microsoft-365\/business\/scheduling-and-booking-app\">Business Schedule and Booking API<\/a>.<\/li>\n<\/ul>\n<p><strong>Function Calling Enabled\u00a0Models<\/strong><\/p>\n<p>This sample uses function calling capable models and has been tested with the following models:<\/p>\n<table>\n<thead>\n<tr>\n<td><strong>Model type<\/strong><\/td>\n<td><strong>Model name\/id<\/strong><\/td>\n<td><strong>Model version<\/strong><\/td>\n<td><strong>Supported<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-3.5-turbo<\/td>\n<td>0125<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-3.5-turbo-1106<\/td>\n<td>1106<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-3.5-turbo-0613<\/td>\n<td>0613<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-3.5-turbo-0301<\/td>\n<td>0301<\/td>\n<td>\u274c<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-3.5-turbo-16k<\/td>\n<td>0613<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4<\/td>\n<td>0613<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4-0613<\/td>\n<td>0613<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4-0314<\/td>\n<td>0314<\/td>\n<td>\u274c<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4-turbo<\/td>\n<td>2024-04-09<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4-turbo-2024-04-09<\/td>\n<td>2024-04-09<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4-turbo-preview<\/td>\n<td>0125-preview<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4-0125-preview<\/td>\n<td>0125-preview<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4-vision-preview<\/td>\n<td>1106-vision-preview<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>Chat Completion<\/td>\n<td>gpt-4-1106-vision-preview<\/td>\n<td>1106-vision-preview<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2139\ufe0f OpenAI Models older than 0613 version do not support function calling.<\/p>\n<p>\u2139\ufe0f When using Azure OpenAI, ensure that the model name of your deployment matches any of the above supported models names.<\/p>\n<p><strong>Configuring the\u00a0sample<\/strong><\/p>\n<p>The sample can be configured by using the command line with .NET\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/aspnet\/core\/security\/app-secrets\">Secret Manager<\/a>\u00a0to avoid the risk of leaking secrets into the repository, branches and pull requests.<\/p>\n<p><strong>Create an App Registration in Azure Active\u00a0Directory<\/strong><\/p>\n<ol>\n<li>Go to the\u00a0<a href=\"https:\/\/portal.azure.com\/\">Azure Portal<\/a>.<\/li>\n<li>Select the Azure Active Directory service.<\/li>\n<li>Select App registrations and click on New registration.<\/li>\n<li>Fill in the required fields and click on Register.<\/li>\n<li>Copy the Application\u00a0<strong>(client) Id<\/strong>\u00a0for later use.<\/li>\n<li>Save Directory\u00a0<strong>(tenant) Id<\/strong>\u00a0for later use..<\/li>\n<li>Click on Certificates &amp; secrets and create a new client secret. (Any name and expiration date will work)<\/li>\n<li>Copy the\u00a0<strong>client secret<\/strong>\u00a0value for later use.<\/li>\n<li>Click on API permissions and add the following permissions:\n<ul>\n<li>Microsoft\u00a0Graph\n<ul>\n<li>Application\u00a0permissions\n<ul>\n<li>BookingsAppointment.ReadWrite.All<\/li>\n<\/ul>\n<\/li>\n<li>Delegated permissions\n<ul>\n<li>OpenId\u00a0permissions\n<ul>\n<li>offline_access<\/li>\n<li>profile<\/li>\n<li>openid<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>Create Or Use a Booking Service and Business<\/strong><\/p>\n<ol>\n<li>Go to the\u00a0<a href=\"https:\/\/outlook.office.com\/bookings\">Bookings Homepage<\/a>\u00a0website.<\/li>\n<li>Create a new Booking Page and add a Service to the Booking (Skip if you don&#8217;t ).<\/li>\n<li>Access\u00a0<a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/graph-explorer\">Graph Explorer<\/a><\/li>\n<li>Run\u00a0the following query to get the Booking Business Id:<\/li>\n<\/ol>\n<p>GET https:\/\/graph.microsoft.com\/v1.0\/solutions\/bookingBusinesses<\/p>\n<ol>\n<li>Copy the\u00a0<strong>Booking Business Id<\/strong>\u00a0for later use.<\/li>\n<li>Run the following query and replace it with your\u00a0<strong>Booking Business Id<\/strong>\u00a0to get the Booking Service Id<\/li>\n<\/ol>\n<p>GET https:\/\/graph.microsoft.com\/v1.0\/solutions\/bookingBusinesses\/{bookingBusiness-id}\/services<\/p>\n<ol>\n<li>Copy the\u00a0<strong>Booking Service Id<\/strong>\u00a0for later use.<\/li>\n<\/ol>\n<p><strong>Using .NET\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/aspnet\/core\/security\/app-secrets\">Secret Manager<\/a><\/strong><\/p>\n<pre>dotnet user-secrets set \"BookingServiceId\" \" .. your Booking Service Id .. \"\r\ndotnet user-secrets set \"BookingBusinessId\" \" .. your Booking Business Id ..\u00a0 \"\r\n\r\ndotnet user-secrets set \"AzureEntraId:TenantId\" \" ... your tenant id ... \"\r\ndotnet user-secrets set \"AzureEntraId:ClientId\" \" ... your client id ... \"\r\n\r\n# App Registration Authentication\r\ndotnet user-secrets set \"AzureEntraId:ClientSecret\" \" ... your client secret ... \"\r\n\r\n# OR User Authentication (Interactive)\r\ndotnet user-secrets set \"AzureEntraId:InteractiveBrowserAuthentication\" \"true\"\r\ndotnet user-secrets set \"AzureEntraId:RedirectUri\" \" ... your redirect uri ... \"\r\n\r\n# OpenAI (Not required if using Azure OpenAI)\r\ndotnet user-secrets set \"OpenAI:ModelId\" \"gpt-3.5-turbo\"\r\ndotnet user-secrets set \"OpenAI:ApiKey\" \"... your api key ... \"\r\ndotnet user-secrets set \"OpenAI:OrgId\" \"... your ord ID ... \" # (Optional)\r\n\r\n# Using Azure OpenAI (Not required if using OpenAI)\r\ndotnet user-secrets set \"AzureOpenAI:DeploymentName\" \" ... your deployment name ... \"\r\ndotnet user-secrets set \"AzureOpenAI:ApiKey\" \" ... your api key ... \"\r\ndotnet user-secrets set \"AzureOpenAI:Endpoint\" \" ... your endpoint ... \"\r\n<\/pre>\n<p><strong>Running the Sample<\/strong><\/p>\n<p>After configuring the sample, to build and run the console application just hit\u00a0F5.<\/p>\n<p>To build and run the console application from the terminal use the following commands:<\/p>\n<pre>dotnet build\r\ndotnet run\r\n<\/pre>\n<p><strong>Example of a Conversation<\/strong><\/p>\n<blockquote><p><strong>User<\/strong>\u00a0&gt; Please book a restaurant for me.<\/p><\/blockquote>\n<blockquote><p><strong>Assistant<\/strong>\u00a0&gt; Sure, I can help you with that. Could you please provide me with the following information:<\/p>\n<ol>\n<li>Name of the restaurant you would like to book.<\/li>\n<li>Date and time of the reservation.<\/li>\n<li>Number of people in your party.<\/li>\n<li>Your name.<\/li>\n<li>Your email address.<\/li>\n<li>Your phone number.<\/li>\n<\/ol>\n<p>Once I have all this information, I will proceed with the booking.<\/p><\/blockquote>\n<blockquote><p><strong>User<\/strong>\u00a0&gt; I would like to book a table at the restaurant &#8220;The French Laundry&#8221; on the 15th of March\u00a0at\u00a07:00 PM for 4 people. My name is John Doe, my email address is\u00a0<a href=\"mailto:john@internet.com\">john@internet.com<\/a>, and my phone number is 123-456-7890.<\/p><\/blockquote>\n<blockquote><p><strong>System<\/strong>\u00a0&gt; Do you want to book a table at The French Laundry on 15\/03\/2023 19:00:00 for 4 people?<\/p><\/blockquote>\n<blockquote><p><strong>System<\/strong>\u00a0&gt; Please confirm by typing &#8216;yes&#8217; or &#8216;no&#8217;.<\/p><\/blockquote>\n<blockquote><p><strong>User<\/strong>\u00a0&gt; yes<\/p><\/blockquote>\n<blockquote><p><strong>Assistant<\/strong>\u00a0&gt; Great! I have successfully booked a table for you at &#8220;The French Laundry&#8221; on the\u00a015th\u00a0of March at 7:00 PM for 4 people.\nYour reservation has been made under the name John Doe.\nIf you have any further questions or need to make any changes to your reservation, please let me know.<\/p><\/blockquote>\n<blockquote><p><strong>User<\/strong>\u00a0&gt; List my current bookings<\/p><\/blockquote>\n<blockquote><p><strong>Assistant<\/strong>\u00a0&gt; You currently have one booking:<\/p>\n<ul>\n<li>Restaurant: The French Laundry<\/li>\n<li>Date and Time: 15th of March at 7:00\u00a0PM<\/li>\n<li>Party Size: 4\u00a0people<\/li>\n<\/ul>\n<p>If you need any further assistance or if there&#8217;s anything else I can help you with, please let me know.<\/p><\/blockquote>\n<blockquote><p><strong>User<\/strong>\u00a0&gt; Cancel my booking<\/p><\/blockquote>\n<blockquote><p><strong>System<\/strong>\u00a0&gt;\u00a0[Cancelling a reservation for 4 at The French Laundry on 2023-03-15 at 19:00:00]<\/p><\/blockquote>\n<blockquote><p><strong>Assistant<\/strong>\u00a0&gt; I have successfully canceled your booking at &#8220;The French Laundry&#8221; on the 15th of March at 7:00 PM for 4 people.<\/p><\/blockquote>\n<p><strong>Dive Deeper<\/strong><\/p>\n<p>Please reach out if you have any questions or feedback through our <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/discussions\/categories\/general\">Semantic Kernel GitHub Discussion Channel<\/a>. We look forward to hearing from you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi all, With Microsoft Build approaching, we wanted to share some walk throughs and samples of Semantic Kernel. Today we&#8217;re going to dive into a Restaurant booking sample to showcase multiple features of Semantic Kernel. This\u00a0sample\u00a0provides\u00a0a\u00a0practical\u00a0demonstration\u00a0of\u00a0how\u00a0to leverage\u00a0features\u00a0from the\u00a0Semantic Kernel\u00a0to build a\u00a0console\u00a0application. Specifically, the application utilizes the\u00a0Business Schedule and\u00a0Booking\u00a0API\u00a0through\u00a0Microsoft\u00a0Graph\u00a0to\u00a0enable\u00a0a Large Language Model (LLM) to book restaurant [&hellip;]<\/p>\n","protected":false},"author":149071,"featured_media":2365,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,1],"tags":[48,63,67,9,77],"class_list":["post-2625","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-samples","category-semantic-kernel","tag-ai","tag-microsoft-semantic-kernel","tag-plugin","tag-semantic-kernel","tag-timeplugin"],"acf":[],"blog_post_summary":"<p>Hi all, With Microsoft Build approaching, we wanted to share some walk throughs and samples of Semantic Kernel. Today we&#8217;re going to dive into a Restaurant booking sample to showcase multiple features of Semantic Kernel. This\u00a0sample\u00a0provides\u00a0a\u00a0practical\u00a0demonstration\u00a0of\u00a0how\u00a0to leverage\u00a0features\u00a0from the\u00a0Semantic Kernel\u00a0to build a\u00a0console\u00a0application. Specifically, the application utilizes the\u00a0Business Schedule and\u00a0Booking\u00a0API\u00a0through\u00a0Microsoft\u00a0Graph\u00a0to\u00a0enable\u00a0a Large Language Model (LLM) to book restaurant [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/2625","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\/149071"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=2625"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/2625\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/2365"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=2625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=2625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=2625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}