I cannot access the training phrases of an intent using the dialogflow client. Please, follow along this example in order to reproduce this behavior.
GoogleCredentials credential = GoogleCredentials
.fromStream(new FileInputStream("./credentials/dialogflow_credentials.json"));
IntentsSettings intentsSettings = IntentsSettings.newBuilder().
setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();
try(IntentsClient intentsClient = IntentsClient.create(intentsSettings)) {
ProjectAgentName parent = ProjectAgentName.of("testtrainingphrases");
for (Intent i : intentsClient.listIntents(parent).iterateAll()){
int count = i.getTrainingPhrasesCount();
System.out.println(count);
}
}
Here is my example agent
TestTrainingPhrases.zip
Here is the sample project (you need to add your credential files)
dfvalidationtest.zip
Hope I could provide a reproducible example.
Thanks!
The API by default does not return all fields of an Intent. Training phrases is one of those fields that will only be returned if you specify that you want all fields to be returned in your get/list request. The current client library does not allow you to specify this option in the normal list and get methods, but you can do it by creating a get/list request your self. This example returns a list of all Intents of the project, including the training phrases:
GoogleCredentials credential = GoogleCredentials
.fromStream(new FileInputStream("/home/loite/CloudSpannerKeys/olavtest-key.json"));
IntentsSettings intentsSettings = IntentsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();
try (IntentsClient intentsClient = IntentsClient.create(intentsSettings)) {
ProjectAgentName parent = ProjectAgentName.of("olav-test-99e2a");
ListIntentsRequest request = ListIntentsRequest.newBuilder()
.setParent(String.format("projects/%s/agent", parent.getProject()))
.setIntentView(IntentView.INTENT_VIEW_FULL).build();
for (Intent i : intentsClient.listIntents(request).iterateAll()) {
System.out.println(i.toString());
for (TrainingPhrase phrase : i.getTrainingPhrasesList()) {
System.out.println(phrase);
}
int count = i.getTrainingPhrasesCount();
System.out.println(count);
}
}
The important part is the ListIntentsRequest.newBuilder().setParent(String.format("projects/%s/agent", parent.getProject())).setIntentView(IntentView.INTENT_VIEW_FULL).build() part. The IntentView.INTENT_VIEW_FULL specifies that you want to receive all fields of the Intent. Note that you need to set the entire parent path yourself, instead of only the parent name (this is what the String.format("projects/%s/agent", parent.getProject()) part does).
Please let me know by reopening the issue if this does not solve your problem.
Most helpful comment
The API by default does not return all fields of an Intent. Training phrases is one of those fields that will only be returned if you specify that you want all fields to be returned in your get/list request. The current client library does not allow you to specify this option in the normal list and get methods, but you can do it by creating a get/list request your self. This example returns a list of all Intents of the project, including the training phrases:
The important part is the
ListIntentsRequest.newBuilder().setParent(String.format("projects/%s/agent", parent.getProject())).setIntentView(IntentView.INTENT_VIEW_FULL).build()part. TheIntentView.INTENT_VIEW_FULLspecifies that you want to receive all fields of the Intent. Note that you need to set the entire parent path yourself, instead of only the parent name (this is what theString.format("projects/%s/agent", parent.getProject())part does).Please let me know by reopening the issue if this does not solve your problem.