{"id":2671,"date":"2024-05-21T08:36:47","date_gmt":"2024-05-21T15:36:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=2671"},"modified":"2024-05-21T08:36:47","modified_gmt":"2024-05-21T15:36:47","slug":"use-semantic-kernel-to-create-a-restaurant-bookings-sample-with-python","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/use-semantic-kernel-to-create-a-restaurant-bookings-sample-with-python\/","title":{"rendered":"Use Semantic Kernel to create a Restaurant Bookings Sample with Python"},"content":{"rendered":"<p>Hi all,<\/p>\n<p>We\u2019re looking forward to highlight a Python sample today focused on a Restaurant Bookings sample <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/main\/python\/samples\/demos\/booking_restaurant\">here<\/a>.<\/p>\n<p><strong>Booking\u00a0Restaurant\u00a0&#8211;\u00a0Demo\u00a0Application<\/strong><\/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. This sample will introduce a kernel syntax example that shows how to integrate with the Microsoft Graph API to create a Restaurant Booking. Note, this doesn&#8217;t place a real reservation, but shows how to interact with MS Graph.<\/p>\n<p><strong>Semantic Kernel Features\u00a0Used<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/main\/python\/samples\/concepts\/plugins\">Plugin<\/a>\u00a0&#8211; Creating a Python Bookings Plugin shown here: <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/python\/samples\/demos\/booking_restaurant\/bookings_plugin\/bookings_plugin.py\">bookings_plugin.py<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/main\/python\/samples\/concepts\/chat_completion\">Chat Completion Service<\/a>\u00a0&#8211; Using the Chat Completion Service\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/python\/samples\/concepts\/chat_completion\/chat_gpt_api.py\">Chat GPT API <\/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> &#8211; Using 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> &#8211; Enables the LLM to have knowledge of current imported plugins using the Function Calling feature, which automatically calls the Booking Plugin from the LLM.<\/li>\n<\/ul>\n<p><strong>Prerequisites<\/strong><\/p>\n<ul>\n<li>Python 3.10, 3.11 or 3.12.<\/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>Configuring the\u00a0Sample<\/strong><\/p>\n<p>The sample can be configured by using either environment variables, a .env file, or manually supplying the required parameters as covered in the sample&#8217;s <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/python\/samples\/demos\/booking_restaurant\/README.md#configuring-the-sample\">README<\/a>.<\/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>Below are the fields you&#8217;ll need to update, as called out above:<\/strong><\/p>\n<ul dir=\"auto\">\n<li>&#8220;BOOKING_SAMPLE_CLIENT_ID&#8221;<\/li>\n<li>&#8220;BOOKING_SAMPLE_TENANT_ID&#8221;<\/li>\n<li>&#8220;BOOKING_SAMPLE_CLIENT_SECRET&#8221;<\/li>\n<li>&#8220;BOOKING_SAMPLE_BUSINESS_ID&#8221;<\/li>\n<li>&#8220;BOOKING_SAMPLE_SERVICE_ID&#8221;<\/li>\n<\/ul>\n<p><strong>Running the Sample<\/strong><\/p>\n<p>After configuring the sample, you&#8217;re ready to run it. The sample should return a conversation similar to the one below.<\/p>\n<p><strong>Example of a Conversation<\/strong><\/p>\n<p><strong>User<\/strong>\u00a0&gt; Please book a restaurant for me.<\/p>\n<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>\n<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>\n<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>\n<p><strong>System<\/strong>\u00a0&gt; Please confirm by typing &#8216;yes&#8217; or &#8216;no&#8217;.<\/p>\n<p><strong>User<\/strong>\u00a0&gt; yes<\/p>\n<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.<\/p>\n<p>Your reservation has been made under the name John Doe.<\/p>\n<p>If you have any further questions or need to make any changes to your reservation, please let me know.<\/p>\n<p><strong>User<\/strong>\u00a0&gt; List my current bookings<\/p>\n<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>\n<p><strong>User<\/strong>\u00a0&gt; Cancel my booking<\/p>\n<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>\n<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>\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, We\u2019re looking forward to highlight a Python sample today focused on a Restaurant Bookings sample here. Booking\u00a0Restaurant\u00a0&#8211;\u00a0Demo\u00a0Application 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 appointments efficiently. This guide will walk you\u00a0through\u00a0the\u00a0necessary\u00a0steps\u00a0to integrate these technologies seamlessly. This sample will introduce a [&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":[33,2,1],"tags":[48,63,53,9],"class_list":["post-2671","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-samples","category-semantic-kernel","tag-ai","tag-microsoft-semantic-kernel","tag-python","tag-semantic-kernel"],"acf":[],"blog_post_summary":"<p>Hi all, We\u2019re looking forward to highlight a Python sample today focused on a Restaurant Bookings sample here. Booking\u00a0Restaurant\u00a0&#8211;\u00a0Demo\u00a0Application 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 appointments efficiently. This guide will walk you\u00a0through\u00a0the\u00a0necessary\u00a0steps\u00a0to integrate these technologies seamlessly. This sample will introduce a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/2671","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=2671"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/2671\/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=2671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=2671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=2671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}