Overview¶
The Conversational Shopping Agent deployment guide provides step-by-step instructions on how to set up and deploy cloud resources for the Conversational Shopping Agent application.
This guide will guide you through enabling necessary services, configuring Dialogflow, Retail Search, and DHL integration.
By following the instructions in this guide, you will be able to set up the required infrastructure and configure the application components, allowing you to experience the power of conversational AI in the retail domain.
Reference Architecture¶
The following diagram illustrates the solution architecture.
- A web application with Dialogflow Messenger embedded as the frontend user interface.
- The Agent uses Open API tools to search and recommend products to the end customer.
- The Agent uses Application Integration tools to fetch delivery status.
Deploy the solution¶
Before you start¶
- Create a billing enabled Google Cloud project.
- Update your constraints/iam.allowedPolicyMemberDomains organization policy: To allow external domain members if not already.
- Go to Cloud shell and clone this repository.
git clone https://github.com/googlecloudplatform/cloud-solutions && \
cd cloud-solutions/projects/conversational-commerce-agent
Enable Services¶
gcloud auth application-default login
export PROJECT_ID=<PROJECT_ID>
gcloud config set project $PROJECT_ID
gcloud auth application-default set-quota-project $PROJECT_ID
gcloud services enable cloudresourcemanager.googleapis.com \
cloudfunctions.googleapis.com \
serviceusage.googleapis.com \
firestore.googleapis.com \
compute.googleapis.com \
cloudbuild.googleapis.com \
storage.googleapis.com \
run.googleapis.com \
retail.googleapis.com \
dialogflow.googleapis.com \
connectors.googleapis.com \
secretmanager.googleapis.com \
iam.googleapis.com \
iamcredentials.googleapis.com
Update Organization Policy¶
Update the iam.allowedPolicyMemberDomains
organization policy to Allow All
,
if required.
Provision Cloud Resources¶
You will use the provided terraform script to provision the following resources:
- The Conversational Agent,
- A Cloud Run that hosts a demo web page
- A Cloud Functions
- Application Integration.
Here are the steps:
- Change to application folder.
- Apply Terraform
The demo solution support three use cases - Apparel, Food and Beauty.
export USECASE_COMPONENT="apparel" # or "beauty", "food"
terraform init
terraform apply -var project_id="$PROJECT_ID" -var component="$USECASE_COMPONENT"
When instructed, answer "yes".
You should see output like below:
agent_gs_bucket = "gs://<project-id>-dialogflowcx-assets"
app_integraion = "./app-integration.json"
demo_ui_cloudrun_url = "https://<cloudrun-service-id>.<region>.run.app"
Take note of the following:
agent_gs_bucket
you will use this bucket laterapp_integration
the json file you will use to create the application integrationui_cloudrun_url
the url of the ui, you will use this ui to interact with the Conversational Agent
Create Application Integration¶
- Find the Application Integration json file
in the working directory when you run
terraform apply
. The filename is in the terraform outputapp_integration
-
Use the json file to Create an integration
-
Choosing apparel-search-prod as the name.
-
Set the region to us-central1.
- Click the Publish button to publish integrations.
-
Enable Unauthenticated API in Conversational Agent¶
- Go to the Conversational Agent console.
- In the project selection page, choose your project.
- In the Agents selection page, select the Conversational Commerce Agent.
- In the left panel, select Integrations, then select Conversational Messenger,
click Connect.
- Make sure “Unauthenticated API (anonymous access)” is checked.
- Scroll down and click the “Enable unauthorized API” button.
- Wait for the API to enable, then click Done to close the dialog.
Search for Commerce Data Import¶
In this demo, we are using the public Flipkart dataset for products. This section introduces the steps to convert the public dataset to Google Cloud Search for Commerce data format, and import the converted data into Search for Commerce.
Enable Search for Commerce service¶
- Goto Search for Commerce Console.
- Follow the instructions to turn on the APIs, agree to data use terms and turn on search & browse features.
- Goto [Vertex AI Search for Commerce API Manage console]
(https://console.cloud.google.com/apis/api/retail.googleapis.com/).
- Wait several seconds until the
Create Credentials
button shows up. - Click the
Create Credentials
button on the top right to create a service account and associate it with the Search for Commerce service- In the Which API are you using? page. Leave Select an API field default, and choose Application Data
- In the Service account details page. Name the service account
retail-service
- in the Grant this service account access to project page.
Grant
Retail Admin, Storage Object Viewer
andStorage Admin
role to the service account. - Click Done to create the service account.
- Wait several seconds until the
Import data to Search for Commerce¶
These scripts report errors if the Search for Commerce service is not ready for use, if you see errors when running the following scripts. Please wait 5 minutes and try again.
This demo solution consists of three different use cases - Apparel, Cosmetic and Food.
- Create Python Virtual environment.
cd ../data-ingestion
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt --require-hashes
- Setup environment variables.
export PROJECT_ID=<YOUR PROJECT ID>
gcloud config set project $PROJECT_ID
export PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID \
--format="value(projectNumber)")
echo $PROJECT_NUMBER
- Convert data file and import data to Search for Commerce.
Note that in this demo, we use Branch 1 as the default branch.
For more information about Search for Commerce Branches, please see the documentation.
- Choose one of the following use cases.
To setup Apparel use case demo¶
Switch to the data-ingestion folder and download Flipkart dataset.
mkdir -p dataset
# Download dataset
curl -L -o \
dataset/archive.zip https://www.kaggle.com/api/v1/datasets/download/PromptCloudHQ/flipkart-products
unzip dataset/archive.zip -d dataset
# Convert data format
python3 flipkart_to_retail_search.py \
-i dataset/flipkart_com-ecommerce_sample.csv \
-o dataset/flipkart-all.jsonl -p $PROJECT_NUMBER -b 1
- Go to Next Step
To setup Cosmetic use case demo¶
Switch to the data-ingestion folder and download Flipkart cosmetic dataset.
mkdir -p dataset
# Download dataset
curl -L -o \
dataset/archive.zip https://www.kaggle.com/api/v1/datasets/download/shivd24coder/cosmetic-brand-products-dataset
unzip dataset/archive.zip -d dataset
# Convert data format
python3 cosmetics_to_retail_search.py \
-i dataset/makeup_data.json \
-o dataset/flipkart-all.jsonl -p $PROJECT_NUMBER -b 1
- Go to Next Step
To setup Food use case demo¶
Switch to the data-ingestion folder and download Flipkart cosmetic dataset
Note that errors may be thrown as some products do not have an image url. Please ignore missing image error.
mkdir -p dataset
# Download dataset
curl -L -o \
dataset/archive.zip https://www.kaggle.com/api/v1/datasets/download/graphquest/restaurant-menu-items
unzip dataset/archive.zip -d dataset
# Convert data format
python3 food_to_retail_search.py \
-i dataset/restaurantmenuchanges.csv \
-o dataset/flipkart-all.jsonl -p $PROJECT_NUMBER -b 1
- Go to Next Step
Import data and set the default branch¶
- Update Search for Commerce catalog level attribute controls.
-
Note that large catalog imports can take hours to fully propagate. Before the data is fully propagated your conversation with the agent may end up with no search results.
-
For demo purposes, you may want to reduce the size of the final dataset to reduce the time of import.
-
Catalog and product information is imported to Branch 1, which is set as the default branch.
export BUCKET_NAME=${PROJECT_ID}-dialogflowcx-${USECASE_COMPONENT}-assets
python3 import_to_retail_search.py -i dataset/flipkart-all.jsonl -g $BUCKET_NAME \
-n $PROJECT_NUMBER -b 1 --set-default-branch
You may see errors below, which indicates this product has invalid data. The problematic product will be ignored and not imported to Search for Commerce.
INFO:root:error_samples {
code: 3
message: "The string in \"product.attributes.value.text\" must be with a length limit of 256 Unicode characters, but 1447 Unicode characters found."
details {
type_url: "type.googleapis.com/google.rpc.ResourceInfo"
value: "\022Fgs://kalschi-conv-commerce-11-dialogflowcx-assets/flipkart-all.jsonl:2"
}
}
Verify the deployment¶
-
Go to Cloud Console, Search for Commerce. In the left panel, goto Controls, Attribute Controls. Make sure the following attributes are made Searchable and Retrivable.
- attributes.Tags
- title
- description
- Name
-
Navigate to
ui_cloudrun_url
you noted down in the previous step. -
Follow the demo guide to verify the deployment.
Troubleshooting¶
Agent returns no product but asks which product I want¶
- Go to Cloud Run, apparel-search-cf, Logs
- Check the latest Cloud Run calls. If you see products in the response payload like below where some products do not have details. The dataset is not fully propagated, please wait a moment and try again.
Log |
---|
RAW RESULT: [{'id': 'a0f262830d970a2921ca58ce6177fdbc', 'product': {'name': 'projects/646255812645/locations/global/catalogs/default_catalog/branches/1/products/a0f262830d970a2921ca58ce6177fdbc'}}, ... |
Retail Search Exception: 'title' |