This module is an example how to create and update entities for Dialogflow.
- Cloud Storage
- Cloud Functions
- Dialogflow
Python 3
.
└── dialogflow_webhook_bank_example
├── main.py # Implementation of examples how to load entities in Dialogflow
├── entities.json # file with entities to be load in a json format
├── requirements.txt # Required libraries for this example
How to setup your project for this example can be found here.
Build an agent by following the instructions here.
Upload the entities.json file to a bucket by following the instructions here.
This implementation is deployed on GCP using Cloud Functions. More info here.
To run the Python scripts on GCP, the gcloud
command-line tool from the Google Cloud SDK is needed.
Refer to the installation page for the appropriate
instructions depending on your platform.
Note that this project has been tested on a Unix-based environment.
After installing, make sure to initialize your Cloud project:
`$ gcloud init`
Use the EntityTypesClient.create_entity_type to create entities one by one.
Client for Dialogflow API - EntityTypeClient.create_entity_type
Run the sample using gcloud util as followed:
$ gcloud functions call entities_builder --data '{
"entities": [{
"display_name":
"saving-account-types",
"kind": "KIND_MAP",
"entities": [{
"value": "saving-account-types",
"synonyms": [
"saving",
"saving account",
"child saving",
"IRA",
"CD",
"student saving"]
}]
}, {
"display_name":
"checking-account-types",
"kind": "KIND_MAP",
"entities": [{
"value":
"checking-account-types",
"synonyms": [
"checking", "checking account", "student checking account",
"student account", "business checking account", "business account"
]
}]
}, {
"display_name": "account_types",
"kind": "KIND_LIST",
"entities": [
{
"value": "@saving-account-types:saving-account-types",
"synonyms": [
"@saving-account-types:saving-account-types"
]
},
{
"value": "@checking-account-types:checking-account-types",
"synonyms": [
"@checking-account-types:checking-account-types"
]
},
{
"value": "@sys.date-period:date-period @saving-account-types:saving-account-types",
"synonyms": [
"@sys.date-period:date-period @saving-account-types:saving-account-types"
]
},
{
"value": "@sys.date-period:date-period @checking-account-types:checking-account-types",
"synonyms": [
"@sys.date-period:date-period @checking-account-types:checking-account-types"
]
}
]
}]
}'
Use the EntityTypesClient.batch_update_entity_types to create or update entities in batch.
Client for Dialogflow API - EntityTypeClient.batch_update_entity_types
BatchUpdateEntityTypesRequest proto
The URI to a Google Cloud Storage file containing entity types to update or create. The URI must start with "gs://". The entities.json file is an example of a json format file that can be uploaded to gcs and passed to the function.
$ gcloud functions call entities_builder --data '{ "bucket": "gs://<bucket_name>/entities.json"}'
For each entity type in the batch:
- The
name
is the the unique identifier of the entity type - If
name
is specified, we update an existing entity type. - If
name
is not specified, we create a new entity type.
$ gcloud functions call entities_builder --data '{
"entities_batch": {
"entity_types":[
{
"name": "5201cee0-ddfb-4f7c-ae94-fff87189d13c",
"display_name":
"saving-account-types",
"kind": "KIND_MAP",
"entities": [{
"value": "saving-account-types",
"synonyms": [
"saving",
"saving account",
"child saving",
"IRA",
"CD",
"student saving",
"senior saving"]
}]
},
{
"display_name":
"checking-account-types",
"kind": "KIND_MAP",
"entities": [{
"value":
"checking-account-types",
"synonyms": [
"checking", "checking account", "student checking account",
"student account", "business checking account", "business account"
]
}]
},
{
"display_name": "account_types",
"kind": "KIND_LIST",
"entities": [
{
"value": "@saving-account-types:saving-account-types",
"synonyms": [
"@saving-account-types:saving-account-types"
]
},
{
"value": "@checking-account-types:checking-account-types",
"synonyms": [
"@checking-account-types:checking-account-types"
]
},
{
"value": "@sys.date-period:date-period @saving-account-types:saving-account-types",
"synonyms": [
"@sys.date-period:date-period @saving-account-types:saving-account-types"
]
},
{
"value": "@sys.date-period:date-period @checking-account-types:checking-account-types",
"synonyms": [
"@sys.date-period:date-period @checking-account-types:checking-account-types"
]
}
]
}
]
}
}'
└── main
├── creates a map entity
├── create a composite entity
├── updates a map entity
Below the definition of the entities.
Define synonyms: true
{
"value": "saving-account-types",
"synonyms": [
"saving",
"saving account",
"child saving",
"IRA",
"CD"
]
}
Define synonyms: true
{
"value": "checking-account-types",
"synonyms": [
"checking",
"checking account",
"student checking account",
"student account",
"business checking account",
"business account"
]
}
{
"value": "@saving-account-type:saving-account-type",
"synonyms": [
"@saving-account-type:saving-account-type"
]
},
{
"value": "@checking-account-type:checking-account-type",
"synonyms": [
"@checking-account-type:checking-account-type"
]
},
{
"value": "@sys.date-period:date-period @saving-account-type:saving-account-type",
"synonyms": [
"@sys.date-period:date-period @saving-account-type:saving-account-type"
]
},
{
"value": "@sys.date-period:date-period @checking-account-type:checking-account-type",
"synonyms": [
"@sys.date-period:date-period @checking-account-type:checking-account-type"
]
}