pythondialogflow-es

Dialogflow doesn't return training phrases


I am trying to get an overview of the training phrases per intent from Dialogflow in python.

I have followed this example to generate the following code:

from google.cloud import dialogflow_v2

# get_credentials is a custom function that loads the credentials
credentials, project_id = get_credentials()

client = dialogflow_v2.IntentsClient(credentials=credentials)

request = dialogflow_v2.ListIntentsRequest(
    parent=f"projects/{project_id}/agent/environments/draft",
)
page_result = client.list_intents(request=request)

for intent in page_result:
    print("Intent name: ", intent.name)
    print("Intent display_name: ", intent.display_name)
    print("Training phrases: ", intent.training_phrases)

The name and display name of the intent are printed as expected, however training phrases is always an empty list (for both the draft as the test environment). Any ideas on why I'm not seeing the training phrases that I can see in the console?

EDIT After hkanjih's answer I've updated my code as follows:

from google.cloud import dialogflow_v2

# get_credentials is a custom function that loads the credentials
credentials, project_id = get_credentials()

client = dialogflow_v2.IntentsClient(credentials=credentials)

request = dialogflow_v2.ListIntentsRequest(
    parent=f"projects/{project_id}/agent/environments/draft",
)
page_result = client.list_intents(request=request)

for intent in page_result:
    print("Intent name: ", intent.name)
    # intent.name is equal to projects/{project_id}/agent/intents/{intent_id}
    intent_request = dialogflow_v2.GetIntentRequest(
        name=intent.name,
    )
    intent = client.get_intent(request=intent_request)
    
    # printing intent name again just to check if it's the same (it is)
    print("Intent name: ", intent.name)
    print("Intent display_name: ", intent.display_name)
    print("Training phrases: ", intent.training_phrases)

Unfortunately, for all intents: Training phrases: []


Solution

  • After searching in the documentation some more, I found this page. Therefore I added the intent_view parameter to the request as in the snippet below:

    from google.cloud import dialogflow_v2
    
    # get_credentials is a custom function that loads the credentials
    _credentials, project_id = self._get_credentials()
    
    client = dialogflow_v2.IntentsClient(credentials=_credentials)
    
    request = dialogflow_v2.ListIntentsRequest(
        parent=f"projects/{project_id}/agent/environments/draft",
        intent_view="INTENT_VIEW_FULL",
    )
    
    page_result = client.list_intents(request=request)
    
    for intent in page_result:
        print("Intent name: ", intent.name)
        print("Intent display_name: {}", intent.display_name)
        print("Training phrases: ", intent.training_phrases)
    

    Note that in the request the parent f"projects/{project_id}/agent" (without the environment) gives the same result.