{"id":2679,"date":"2024-05-17T10:38:17","date_gmt":"2024-05-17T17:38:17","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=2679"},"modified":"2024-05-17T10:38:17","modified_gmt":"2024-05-17T17:38:17","slug":"use-semantic-kernel-to-create-a-restaurant-bookings-sample-with-java","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/use-semantic-kernel-to-create-a-restaurant-bookings-sample-with-java\/","title":{"rendered":"Use Semantic Kernel to create a Restaurant Bookings Sample with Java"},"content":{"rendered":"<p>We\u2019re looking forward to highlight a Java sample today focused on a Restaurant Bookings sample <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/java-v1\/java\/samples\/booking-agent-m365\/src\/main\/java\/com\/microsoft\/semantickernel\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p><strong>Booking\u00a0Restaurant\u00a0\u2013\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\" target=\"_blank\" rel=\"noopener\">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\" target=\"_blank\" rel=\"noopener\">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\u2019t 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\/java-development\/java\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/plugins\" target=\"_blank\" rel=\"noopener\">Plugin<\/a>\u00a0\u2013 Creating a Python Bookings Plugin shown here:\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/java-development\/java\/samples\/semantickernel-demos\/booking-agent-m365\/src\/main\/java\/com\/microsoft\/semantickernel\" target=\"_blank\" rel=\"noopener\">Java Booking Agent<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/java-development\/java\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/chatcompletion\" target=\"_blank\" rel=\"noopener\">Chat Completion Service<\/a>\u00a0\u2013 Using the Chat Completion Service to\u00a0generate\u00a0responses from the LLM.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/java-development\/java\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/functions\/Example59_OpenAIFunctionCalling.java\" target=\"_blank\" rel=\"noopener\">Auto Function Calling<\/a>\u00a0Enables the LLM to have knowledge of current imported Using 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>Java prerequisites needed:<\/li>\n<li><a href=\"https:\/\/www.microsoft.com\/en-us\/microsoft-365\/business\/compare-all-microsoft-365-business-products\" target=\"_blank\" rel=\"noopener\">Microsoft 365 Business License<\/a>\u00a0to use\u00a0<a href=\"https:\/\/www.microsoft.com\/en-us\/microsoft-365\/business\/scheduling-and-booking-app\" target=\"_blank\" rel=\"noopener\">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 the command line with\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/aspnet\/core\/security\/app-secrets\" target=\"_blank\" rel=\"noopener\">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\/\" target=\"_blank\" rel=\"noopener\">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\" target=\"_blank\" rel=\"noopener\">Bookings Homepage<\/a>\u00a0website.<\/li>\n<li>Create a new Booking Page and add a Service to the Booking (Skip if you don\u2019t ).<\/li>\n<li>Access\u00a0<a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/graph-explorer\" target=\"_blank\" rel=\"noopener\">Graph Explorer<\/a><\/li>\n<li>Run\u00a0the following query to get the Booking Business Id:<\/li>\n<\/ol>\n<pre tabindex=\"0\">GET https:\/\/graph.microsoft.com\/v1.0\/solutions\/bookingBusinesses<\/pre>\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<pre tabindex=\"0\">GET https:\/\/graph.microsoft.com\/v1.0\/solutions\/bookingBusinesses\/{bookingBusiness-id}\/services<\/pre>\n<ol>\n<li>Copy the\u00a0<strong>Booking Service Id<\/strong>\u00a0for later use.<\/li>\n<\/ol>\n<p>Fill in the following code below:<\/p>\n<pre tabindex=\"0\">\/\/ Config for OpenAI\r\nprivate static final String AZURE_CLIENT_KEY = System.getenv(\"AZURE_CLIENT_KEY\");\r\nprivate static final String CLIENT_ENDPOINT = System.getenv(\"CLIENT_ENDPOINT\");\r\nprivate static final String MODEL_ID = System.getenv().getOrDefault(\"MODEL_ID\", \"gpt-35-turbo-2\");\r\n\r\n\/\/ Config for Graph\r\n\/\/ https:\/\/learn.microsoft.com\/en-us\/graph\/tutorials\/java?tabs=aad&amp;tutorial-step=1\r\nprivate static final String TENANT_ID = System.getenv(\"TENANT_ID\");\r\nprivate static final String CLIENT_ID = System.getenv(\"CLIENT_ID\");\r\n\r\n\/\/ Booking Business ID\r\nprivate static final String BOOKING_BUSINESS_ID = System.getenv(\"BOOKING_BUSINESS_ID\");\r\n\r\n\/\/ Service ID for the booking business\r\nprivate static final String SERVICE_ID = System.getenv(\"SERVICE_ID\");\r\n\r\n\/\/ Must match the redirect URL in the Azure AD app registration\r\nprivate static final String REDIRECT_URL = System.getenv(\"REDIRECT_URL\");<\/pre>\n<p><strong>Running the Sample<\/strong><\/p>\n<p>After configuring the sample, you\u2019re ready to run it. The sample should return the following conversation as seen below.<\/p>\n<p><strong>Example of a Conversation<\/strong><\/p>\n<pre tabindex=\"0\"><strong>User<\/strong>\u00a0&gt; Please book a restaurant for me.\r\n\r\n<strong>Assistant<\/strong>\u00a0&gt; Sure, I can help you with that. Could you please provide me with the following information:\r\n\r\n1. Name of the restaurant you would like to book.\r\n2. Date and time of the reservation.\r\n3. Number of people in your party.\r\n4. Your name.\r\n5. Your email address.\r\n6. Your phone number.\r\n\r\nOnce I have all this information, I will proceed with the booking.\r\n\r\n<strong>User<\/strong>\u00a0&gt; I would like to book a table at the restaurant \"The French Laundry\" 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.\r\n\r\n<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?\r\n\r\n<strong>System<\/strong>\u00a0&gt; Please confirm by typing 'yes' or 'no'.\r\n\r\n<strong>User<\/strong>\u00a0&gt; yes\r\n\r\n<strong>Assistant<\/strong>\u00a0&gt; Great! I have successfully booked a table for you at \"The French Laundry\" on the\u00a015th\u00a0of March at 7:00 PM for 4 people.\r\n\r\nYour reservation has been made under the name John Doe.\r\n\r\nIf you have any further questions or need to make any changes to your reservation, please let me know.\r\n\r\n<strong>User<\/strong>\u00a0&gt; List my current bookings\r\n\r\n<strong>Assistant<\/strong>\u00a0&gt; You currently have one booking:\r\n\r\n- Restaurant: The French Laundry\r\n- Date and Time: 15th of March at 7:00 PM\r\n- Party Size: 4 people\r\n\r\nIf you need any further assistance or if there's anything else I can help you with, please let me know.\r\n\r\n<strong>User<\/strong>\u00a0&gt; Cancel my booking\r\n\r\n<strong>System<\/strong>\u00a0&gt;\u00a0[Cancelling a reservation for 4 at The French Laundry on 2023-03-15 at 19:00:00]\r\n\r\n<strong>Assistant<\/strong>\u00a0&gt; I have successfully canceled your booking at \"The French Laundry\" on the 15th of March at 7:00 PM for 4 people.\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Dive Deeper<\/strong><\/p>\n<p>Please reach out if you have any questions or feedback through our\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/discussions\/categories\/general\" target=\"_blank\" rel=\"noopener\">Semantic Kernel GitHub Discussion Channel<\/a>. We look forward to hearing from you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re looking forward to highlight a Java sample today focused on a Restaurant Bookings sample here. Booking\u00a0Restaurant\u00a0\u2013\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 kernel syntax [&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":[24,2,1],"tags":[48,20,63,9],"class_list":["post-2679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-samples","category-semantic-kernel","tag-ai","tag-java","tag-microsoft-semantic-kernel","tag-semantic-kernel"],"acf":[],"blog_post_summary":"<p>We\u2019re looking forward to highlight a Java sample today focused on a Restaurant Bookings sample here. Booking\u00a0Restaurant\u00a0\u2013\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 kernel syntax [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/2679","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=2679"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/2679\/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=2679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=2679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=2679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}