We’re looking forward to highlight a Java sample today focused on a Restaurant Bookings sample here.
Booking Restaurant – Demo Application
This sample provides a practical demonstration of how to leverage features from the Semantic Kernel to build a console application. Specifically, the application utilizes the Business Schedule and Booking API through Microsoft Graph to enable a Large Language Model (LLM) to book restaurant appointments efficiently. This guide will walk you through the necessary steps to 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’t place a real reservation, but shows how to interact with MS Graph.
Semantic Kernel Features Used
- Plugin – Creating a Python Bookings Plugin shown here: Java Booking Agent
- Chat Completion Service – Using the Chat Completion Service to generate responses from the LLM.
- Auto Function Calling Enables the LLM to have knowledge of current imported Using the Function Calling feature automatically call the Booking Plugin from the LLM.
Prerequisites
- Java prerequisites needed:
- Microsoft 365 Business License to use Business Schedule and Booking API.
Configuring the Sample
The sample can be configured by using the command line with Secret Manager to avoid the risk of leaking secrets into the repository, branches and pull requests.
Create an App Registration in Azure Active Directory
- Go to the Azure Portal.
- Select the Azure Active Directory service.
- Select App registrations and click on new registration.
- Fill in the required fields and click on Register.
- Copy the Application (client) Id for later use.
- Save Directory (tenant) Id for later use.
- Click on Certificates & secrets and create a new client secret. (Any name and expiration date will work)
- Copy the client secret value for later use.
- Click on API permissions and add the following permissions:
- Microsoft Graph
- Application permissions
- BookingsAppointment.ReadWrite.All
- Delegated permissions
- OpenId permissions
- offline_access
- profile
- openid
- OpenId permissions
- Application permissions
- Microsoft Graph
Create Or Use a Booking Service and Business
- Go to the Bookings Homepage website.
- Create a new Booking Page and add a Service to the Booking (Skip if you don’t ).
- Access Graph Explorer
- Run the following query to get the Booking Business Id:
GET https://graph.microsoft.com/v1.0/solutions/bookingBusinesses
- Copy the Booking Business Id for later use.
- Run the following query and replace it with your Booking Business Id to get the Booking Service Id
GET https://graph.microsoft.com/v1.0/solutions/bookingBusinesses/{bookingBusiness-id}/services
- Copy the Booking Service Id for later use.
Fill in the following code below:
// Config for OpenAI private static final String AZURE_CLIENT_KEY = System.getenv("AZURE_CLIENT_KEY"); private static final String CLIENT_ENDPOINT = System.getenv("CLIENT_ENDPOINT"); private static final String MODEL_ID = System.getenv().getOrDefault("MODEL_ID", "gpt-35-turbo-2"); // Config for Graph // https://learn.microsoft.com/en-us/graph/tutorials/java?tabs=aad&tutorial-step=1 private static final String TENANT_ID = System.getenv("TENANT_ID"); private static final String CLIENT_ID = System.getenv("CLIENT_ID"); // Booking Business ID private static final String BOOKING_BUSINESS_ID = System.getenv("BOOKING_BUSINESS_ID"); // Service ID for the booking business private static final String SERVICE_ID = System.getenv("SERVICE_ID"); // Must match the redirect URL in the Azure AD app registration private static final String REDIRECT_URL = System.getenv("REDIRECT_URL");
Running the Sample
After configuring the sample, you’re ready to run it. The sample should return the following conversation as seen below.
Example of a Conversation
User > Please book a restaurant for me. Assistant > Sure, I can help you with that. Could you please provide me with the following information: 1. Name of the restaurant you would like to book. 2. Date and time of the reservation. 3. Number of people in your party. 4. Your name. 5. Your email address. 6. Your phone number. Once I have all this information, I will proceed with the booking. User > I would like to book a table at the restaurant "The French Laundry" on the 15th of March at 7:00 PM for 4 people. My name is John Doe, my email address is john@internet.com, and my phone number is 123-456-7890. System > Do you want to book a table at The French Laundry on 15/03/2023 19:00:00 for 4 people? System > Please confirm by typing 'yes' or 'no'. User > yes Assistant > Great! I have successfully booked a table for you at "The French Laundry" on the 15th of March at 7:00 PM for 4 people. Your reservation has been made under the name John Doe. If you have any further questions or need to make any changes to your reservation, please let me know. User > List my current bookings Assistant > You currently have one booking: - Restaurant: The French Laundry - Date and Time: 15th of March at 7:00 PM - Party Size: 4 people If you need any further assistance or if there's anything else I can help you with, please let me know. User > Cancel my booking System > [Cancelling a reservation for 4 at The French Laundry on 2023-03-15 at 19:00:00] Assistant > I have successfully canceled your booking at "The French Laundry" on the 15th of March at 7:00 PM for 4 people.
Dive Deeper
Please reach out if you have any questions or feedback through our Semantic Kernel GitHub Discussion Channel. We look forward to hearing from you!
0 comments