### Motivation and Context The current `FunctionCallBehavior` has allowed us to utilize auto function calling for OpenAI type models. As we proceed to support more AI connectors, that differ from OpenAI models, we need to be able to handle functions for all models that support function calling. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description In this PR: - We introduce a new function calling abstraction called `FunctionChoiceBehavior` which has three types: Auto, Required, and None. - One is able to configure the `function_choice_behavior` along with fully qualified function names (e.g., plugin1.function1), `maximum_auto_invoke_attempts` or `auto_invoke_kernel_functions` in yaml and JSON prompts. We have a new concept example showing how to do this for for yaml and JSON prompts. - If the fully qualified names are specified in the config file, they take precedence over the filters, if specified at a later point. - To make sure this isn't a breaking change, we still handle the previous `FunctionCallBehavior`, but so we can make decisions on the new `FunctionChoiceBehavior` we map the `FunctionCallBehavior` to `FunctionChoiceBehavior`. Each time `FunctionCallBehavior` is updated, `FunctionChoiceBehavior` will be updated, too. - The `_process_tool_call()` method in the `open_ai_chat_completion_base` needs to maintain the argument name as `function_call_behavior` as we cannot introduce a breaking change. - All concept samples have been converted to use `FunctionChoiceBehavior`. - New unit tests have been added for `FunctionChoiceBehavior` and we still currently support `FunctionCallBehavior` tests to make sure we haven't broken the backwards compatibility. - Added `deprecated` typing decorators to classes/methods to alert users that it would be best to transition to `FunctionChoiceBehavior` even though `FunctionCallBehavior` is still supported. - The `FunctionCallingStepwisePlanner` was updated to use the new `FunctionChoiceBehavior`. - Closes #6496, #6458 - Addresses #6626 <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
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.
Prerequisites
- Python 3.10, 3.11, or 3.12.
- Microsoft 365 Business License to use Business Schedule and Booking API.
- Azure Entra Id administrator account to register an application and set the necessary credentials and permissions.
Function Calling Enabled Models
This sample uses function calling capable models and has been tested with the following models:
| Model type | Model name/id | Model version | Supported |
|---|---|---|---|
| Chat Completion | gpt-3.5-turbo | 0125 | ✅ |
| Chat Completion | gpt-3.5-turbo | 1106 | ✅ |
| Chat Completion | gpt-3.5-turbo-0613 | 0613 | ✅ |
| Chat Completion | gpt-3.5-turbo-0301 | 0301 | ❌ |
| Chat Completion | gpt-3.5-turbo-16k | 0613 | ✅ |
| Chat Completion | gpt-4 | 0613 | ✅ |
| Chat Completion | gpt-4-0613 | 0613 | ✅ |
| Chat Completion | gpt-4-0314 | 0314 | ❌ |
| Chat Completion | gpt-4-turbo | 2024-04-09 | ✅ |
| Chat Completion | gpt-4-turbo-2024-04-09 | 2024-04-09 | ✅ |
| Chat Completion | gpt-4-turbo-preview | 0125-preview | ✅ |
| Chat Completion | gpt-4-0125-preview | 0125-preview | ✅ |
| Chat Completion | gpt-4-vision-preview | 1106-vision-preview | ✅ |
| Chat Completion | gpt-4-1106-vision-preview | 1106-vision-preview | ✅ |
ℹ️ OpenAI Models older than 0613 version do not support function calling.
ℹ️ When using Azure OpenAI, ensure that the model name of your deployment matches any of the above supported models names.
Configuring the sample
Please make sure either your environment variables or your .env file contains the following:
- "BOOKING_SAMPLE_CLIENT_ID"
- "BOOKING_SAMPLE_TENANT_ID"
- "BOOKING_SAMPLE_CLIENT_SECRET"
- "BOOKING_SAMPLE_BUSINESS_ID"
- "BOOKING_SAMPLE_SERVICE_ID"
If wanting to use the .env file, you must pass the env_file_path parameter with a valid path:
booking_sample_settings = BookingSampleSettings(env_file_path=env_file_path)
This will tell Pydantic settings to also load the .env file instead of just trying to load environment variables.
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.
Running the sample
Either run the sample in an IDE, like VSCode, or via the command line.
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:
- Name of the restaurant you would like to book.
- Date and time of the reservation.
- Number of people in your party.
- Your name.
- Your email address.
- 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 [email protected], 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.
If you have any other questions or need further assistance, please let me know.