This project simulates a mock restaurant API to check table availability and make reservations. It is designed to demonstrate how such an API might function, using mock data and responses to mimic real-world API behavior. The project consists of three main components:
mock_restaurant_api.py
- Contains theMockRestaurantAPI
class which provides methods for checking table availability and performing dummy reservations.utils.py
- Contains utility functions to assist with the processing of responses.main.py
- Main script to initialize and interact with the mock API using Vertex AI.
-
check_table_availability
:- Description: Mocks the call to an API to check table availability.
- Parameters:
party_size
,date
,time
,restaurant_name
. - Returns: A tuple with a boolean indicating availability and a message.
-
perform_dummy_reservation
:- Description: Mocks the call to an API to perform a reservation.
- Parameters:
party_size
,date
,time
,restaurant_name
. - Returns: A tuple with a boolean indicating success and a message with a dummy reservation ID.
is_function_calling(response)
:- Description: Determines if there is at least one function call in the response.
- Parameters:
response
(an object containing response data from a Vertex AI agent). - Returns: Boolean indicating if there is a function call in the first candidate response.
- Raises:
ValueError
if the response does not containcandidates
or ifcandidates
is not a list.AttributeError
if the first candidate does not havefunction_calls
attribute.
PROJECT_ID
: Google Cloud project ID.LOCATION
: Google Cloud location.
vertexai
for Vertex AI initialization.requests
for making HTTP requests.
-
Vertex AI Initialization:
- Initializes Vertex AI with the specified project ID and location.
-
Function Declarations:
check_table_availability
: Checks table availability for a given date, time, and party size.place_reservation
: Places a reservation with contact information.
-
Tool Initialization:
restaurant_tool
: Adds declared functions to the tool instance.
-
GenerativeModel Initialization:
- Initializes a
GenerativeModel
with specified model name and configuration.
- Initializes a
-
Chat Session:
- Starts a chat session with the initialized model.
-
Prompt Definition:
- Defines the initial user prompt for checking table availability.
-
Handling Function Calls:
handle_function_call(response)
: Handles function calls extracted from the response.handle_user_message(response)
: Handles user input messages.
-
Process Completion:
complete_process()
: Checks if the reservation process is completed and prints the reservation text if successful.
-
Initialization:
- Ensure you have the required libraries installed (
vertexai
,requests
). - Set the
PROJECT_ID
andLOCATION
inmain.py
.
- Ensure you have the required libraries installed (
-
Running the Script:
- Execute
main.py
to start the mock restaurant API interaction. - Follow the prompts to check table availability and make reservations.
- Execute
Here is an example of how you might interact with the script:
python main.py
When prompted, the script will simulate checking table availability and making reservations using mock data.
This project is licensed under the MIT License.
This README provides an overview of the project, detailed descriptions of the files and functions, and instructions on how to use the script. For further information or questions, please refer to the documentation within the code or reach out to the maintainers.